using System;
using System.Windows.Forms;
using System.Security.Permissions;

public class Form1 : Form
{
    public Form1()
    {
        // Create the form layout. If you are using Visual Studio,
        // you can replace this code with code generated by the designer.
        InitializeForm();

        // The following events are not visible in the designer, so
        // you must associate them with their event-handlers in code.
        webBrowser1.CanGoBackChanged +=
            new EventHandler(webBrowser1_CanGoBackChanged);
        webBrowser1.CanGoForwardChanged +=
            new EventHandler(webBrowser1_CanGoForwardChanged);
        webBrowser1.DocumentTitleChanged +=
            new EventHandler(webBrowser1_DocumentTitleChanged);
        webBrowser1.StatusTextChanged +=
            new EventHandler(webBrowser1_StatusTextChanged);

        // Load the user's home page.
        webBrowser1.GoHome();
    }

    // Displays the Save dialog box.
    private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
    {
        webBrowser1.ShowSaveAsDialog();
    }

    // Displays the Page Setup dialog box.
    private void pageSetupToolStripMenuItem_Click(object sender, EventArgs e)
    {
        webBrowser1.ShowPageSetupDialog();
    }

    // Displays the Print dialog box.
    private void printToolStripMenuItem_Click(object sender, EventArgs e)
    {
        webBrowser1.ShowPrintDialog();
    }

    // Displays the Print Preview dialog box.
    private void printPreviewToolStripMenuItem_Click(
        object sender, EventArgs e)
    {
        webBrowser1.ShowPrintPreviewDialog();
    }

    // Displays the Properties dialog box.
    private void propertiesToolStripMenuItem_Click(
        object sender, EventArgs e)
    {
        webBrowser1.ShowPropertiesDialog();
    }

    // Selects all the text in the text box when the user clicks it.
    private void toolStripTextBox1_Click(object sender, EventArgs e)
    {
        toolStripTextBox1.SelectAll();
    }

    // Navigates to the URL in the address box when
    // the ENTER key is pressed while the ToolStripTextBox has focus.
    private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            Navigate(toolStripTextBox1.Text);
        }
    }

    // Navigates to the URL in the address box when
    // the Go button is clicked.
    private void goButton_Click(object sender, EventArgs e)
    {
        Navigate(toolStripTextBox1.Text);
    }

    // Navigates to the given URL if it is valid.
    private void Navigate(String address)
    {
        if (String.IsNullOrEmpty(address)) return;
        if (address.Equals("about:blank")) return;
        if (!address.StartsWith("http://") &&
            !address.StartsWith("https://"))
        {
            address = "http://" + address;
        }
        try
        {
            webBrowser1.Navigate(new Uri(address));
        }
        catch (System.UriFormatException)
        {
            return;
        }
    }

    // Updates the URL in TextBoxAddress upon navigation.
    private void webBrowser1_Navigated(object sender,
        WebBrowserNavigatedEventArgs e)
    {
        toolStripTextBox1.Text = webBrowser1.Url.ToString();
    }

    // Navigates webBrowser1 to the previous page in the history.
    private void backButton_Click(object sender, EventArgs e)
    {
        webBrowser1.GoBack();
    }

    // Disables the Back button at the beginning of the navigation history.
    private void webBrowser1_CanGoBackChanged(object sender, EventArgs e)
    {
        backButton.Enabled = webBrowser1.CanGoBack;
    }

    // Navigates webBrowser1 to the next page in history.
    private void forwardButton_Click(object sender, EventArgs e)
    {
        webBrowser1.GoForward();
    }

    // Disables the Forward button at the end of navigation history.
    private void webBrowser1_CanGoForwardChanged(object sender, EventArgs e)
    {
        forwardButton.Enabled = webBrowser1.CanGoForward;
    }

    // Halts the current navigation and any sounds or animations on
    // the page.
    private void stopButton_Click(object sender, EventArgs e)
    {
        webBrowser1.Stop();
    }

    // Reloads the current page.
    private void refreshButton_Click(object sender, EventArgs e)
    {
        // Skip refresh if about:blank is loaded to avoid removing
        // content specified by the DocumentText property.
        if (!webBrowser1.Url.Equals("about:blank"))
        {
            webBrowser1.Refresh();
        }
    }

    // Navigates webBrowser1 to the home page of the current user.
    private void homeButton_Click(object sender, EventArgs e)
    {
        webBrowser1.GoHome();
    }

    // Navigates webBrowser1 to the search page of the current user.
    private void searchButton_Click(object sender, EventArgs e)
    {
        webBrowser1.GoSearch();
    }

    // Prints the current document using the current print settings.
    private void printButton_Click(object sender, EventArgs e)
    {
        webBrowser1.Print();
    }

    // Updates the status bar with the current browser status text.
    private void webBrowser1_StatusTextChanged(object sender, EventArgs e)
    {
        toolStripStatusLabel1.Text = webBrowser1.StatusText;
    }

    // Updates the title bar with the current document title.
    private void webBrowser1_DocumentTitleChanged(object sender, EventArgs e)
    {
        this.Text = webBrowser1.DocumentTitle;
    }

    // Exits the application.
    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }

    // The remaining code in this file provides basic form initialization and
    // includes a Main method. If you use the Visual Studio designer to create
    // your form, you can use the designer generated code instead of this code,
    // but be sure to use the names shown in the variable declarations here,
    // and be sure to attach the event handlers to the associated events.

    private WebBrowser webBrowser1;

    private MenuStrip menuStrip1;
    private ToolStripMenuItem fileToolStripMenuItem,
        saveAsToolStripMenuItem, printToolStripMenuItem,
        printPreviewToolStripMenuItem, exitToolStripMenuItem,
        pageSetupToolStripMenuItem, propertiesToolStripMenuItem;
    private ToolStripSeparator toolStripSeparator1, toolStripSeparator2;

    private ToolStrip toolStrip1, toolStrip2;
    private ToolStripTextBox toolStripTextBox1;
    private ToolStripButton goButton, backButton,
        forwardButton, stopButton, refreshButton,
        homeButton, searchButton, printButton;

    private StatusStrip statusStrip1;
    private ToolStripStatusLabel toolStripStatusLabel1;

    private void InitializeForm()
    {
        webBrowser1 = new WebBrowser();

        menuStrip1 = new MenuStrip();
        fileToolStripMenuItem = new ToolStripMenuItem();
        saveAsToolStripMenuItem = new ToolStripMenuItem();
        toolStripSeparator1 = new ToolStripSeparator();
        printToolStripMenuItem = new ToolStripMenuItem();
        printPreviewToolStripMenuItem = new ToolStripMenuItem();
        toolStripSeparator2 = new ToolStripSeparator();
        exitToolStripMenuItem = new ToolStripMenuItem();
        pageSetupToolStripMenuItem = new ToolStripMenuItem();
        propertiesToolStripMenuItem = new ToolStripMenuItem();

        toolStrip1 = new ToolStrip();
        goButton = new ToolStripButton();
        backButton = new ToolStripButton();
        forwardButton = new ToolStripButton();
        stopButton = new ToolStripButton();
        refreshButton = new ToolStripButton();
        homeButton = new ToolStripButton();
        searchButton = new ToolStripButton();
        printButton = new ToolStripButton();

        toolStrip2 = new ToolStrip();
        toolStripTextBox1 = new ToolStripTextBox();

        statusStrip1 = new StatusStrip();
        toolStripStatusLabel1 = new ToolStripStatusLabel();

        menuStrip1.Items.Add(fileToolStripMenuItem);

        fileToolStripMenuItem.DropDownItems.AddRange(
            new ToolStripItem[] {
                saveAsToolStripMenuItem, toolStripSeparator1,
                pageSetupToolStripMenuItem, printToolStripMenuItem,
                printPreviewToolStripMenuItem, toolStripSeparator2,
                propertiesToolStripMenuItem, exitToolStripMenuItem
            });

        fileToolStripMenuItem.Text = "&File";
        saveAsToolStripMenuItem.Text = "Save &As...";
        pageSetupToolStripMenuItem.Text = "Page Set&up...";
        printToolStripMenuItem.Text = "&Print...";
        printPreviewToolStripMenuItem.Text = "Print Pre&view...";
        propertiesToolStripMenuItem.Text = "Properties";
        exitToolStripMenuItem.Text = "E&xit";

        printToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.P;

        saveAsToolStripMenuItem.Click +=
            new System.EventHandler(saveAsToolStripMenuItem_Click);
        pageSetupToolStripMenuItem.Click +=
            new System.EventHandler(pageSetupToolStripMenuItem_Click);
        printToolStripMenuItem.Click +=
            new System.EventHandler(printToolStripMenuItem_Click);
        printPreviewToolStripMenuItem.Click +=
            new System.EventHandler(printPreviewToolStripMenuItem_Click);
        propertiesToolStripMenuItem.Click +=
            new System.EventHandler(propertiesToolStripMenuItem_Click);
        exitToolStripMenuItem.Click +=
            new System.EventHandler(exitToolStripMenuItem_Click);

        toolStrip1.Items.AddRange(new ToolStripItem[] {
            goButton, backButton, forwardButton, stopButton,
            refreshButton, homeButton, searchButton, printButton});

        goButton.Text = "Go";
        backButton.Text = "Back";
        forwardButton.Text = "Forward";
        stopButton.Text = "Stop";
        refreshButton.Text = "Refresh";
        homeButton.Text = "Home";
        searchButton.Text = "Search";
        printButton.Text = "Print";

        backButton.Enabled = false;
        forwardButton.Enabled = false;

        goButton.Click += new System.EventHandler(goButton_Click);
        backButton.Click += new System.EventHandler(backButton_Click);
        forwardButton.Click += new System.EventHandler(forwardButton_Click);
        stopButton.Click += new System.EventHandler(stopButton_Click);
        refreshButton.Click += new System.EventHandler(refreshButton_Click);
        homeButton.Click += new System.EventHandler(homeButton_Click);
        searchButton.Click += new System.EventHandler(searchButton_Click);
        printButton.Click += new System.EventHandler(printButton_Click);

        toolStrip2.Items.Add(toolStripTextBox1);
        toolStripTextBox1.Size = new System.Drawing.Size(250, 25);
        toolStripTextBox1.KeyDown +=
            new KeyEventHandler(toolStripTextBox1_KeyDown);
        toolStripTextBox1.Click +=
            new System.EventHandler(toolStripTextBox1_Click);

        statusStrip1.Items.Add(toolStripStatusLabel1);

        webBrowser1.Dock = DockStyle.Fill;
        webBrowser1.Navigated +=
            new WebBrowserNavigatedEventHandler(webBrowser1_Navigated);

        Controls.AddRange(new Control[] {
            webBrowser1, toolStrip2, toolStrip1,
            menuStrip1, statusStrip1, menuStrip1 });
    }

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
} 

C Sharp Online Compiler

Write, Run & Share C# code online using OneCompiler's C# online compiler for free. It's one of the robust, feature-rich online compilers for C# language, running on the latest version 8.0. Getting started with the OneCompiler's C# compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C# and start coding.

Read inputs from stdin

OneCompiler's C# online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.

using System;
 
namespace Sample
{
  class Test
    {
      public static void Main(string[] args)
       {
         string name;
         name = Console.ReadLine();
         Console.WriteLine("Hello {0} ", name);
	}
     }
}

About C Sharp

C# is a general purpose object-oriented programming language by Microsoft. Though initially it was developed as part of .net but later it was approved by ECMA and ISO standards.

You can use C# to create variety of applications, like web, windows, mobile, console applications and much more using Visual studio.

Syntax help

Data types

Data TypeDescriptionRangesize
intTo store integers-2,147,483,648 to 2,147,483,6474 bytes
doubleto store large floating point numbers with decimalscan store 15 decimal digits8 bytes
floatto store floating point numbers with decimalscan store upto 7 decimal digits4 bytes
charto store single characters-2 bytes
stringto stores text-2 bytes per character
boolto stores either true or false-1 bit

Variables

Syntax

datatype variable-name = value;

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition or set of few conditions IF-ELSE is used.

if(conditional-expression) {
   // code
} 
else {
   // code
}

You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to If-Else-If ladder.

switch(conditional-expression) {    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
...    
    
default:     
 // code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement) {
  // code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition) {
 // code 
}

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {
  // code 
} while (condition);

Arrays

Array is a collection of similar data which is stored in continuous memory addresses. Array values can be fetched using index. Index starts from 0 to size-1.

Syntax

data-type[] array-name;

Methods

Method is a set of statements which gets executed only when they are called. Call the method name in the main function to execute the method.

Syntax

static void method-name() 
{
  // code to be executed
}