HomeSelenium C#

C# for Selenium – First C Sharp Program

C# for Selenium – First C Sharp Program

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

C# for Selenium – First C Sharp Program

Once you have installed Visual Studio as instructed in our previous post (click here to install Visual Studio), you are now ready to execute a C# program in it.

Simple C# Program Execution

Follow the below steps for creating and executing a simple C# Program in Console Application of Visual Studio.

1) Search for ‘Visual Studio’ in your machine and click from the Search results as shown below:

C# for Selenium - Search Visual Studio

2) Observe that the Visual Studio IDE will be launched and Click on the ‘Create a new Project’ option as shown below:

C# for Selenium - Visual Studio Launched

 

3) Select ‘Console C#’ Template and Click on the ‘Next’ button on the displayed ‘Create a new project’ dialog as shown below:

C# for Selenium - Visual Studio Select CSharp Console Template

 

4) In the displayed dialog, provide the project name as ‘MyFirstProject’ and select any desired location on your machine and click on ‘Create’ button as shown below:

C# for Selenium - Create

 

5) Program.cs with default code and Solution Explorer will be opened by default as shown below:

C# for Selenium - Program cs Solution Explorer

6) Write the following line of code inside the Main block as shown below and Save Program.cs file:

The below code will print the given text in to the Output console as it is.

Console.WriteLine("My First C# Program");  //Prints the line of text as Output

C# for Selenium - Console WriteLine

7) Lets execute the line of code written so far by clicking ‘Start’ button on the Visual Studio IDE or by pressing ‘F5’ key on your keyboard as shown below:

C# for Selenium - First Run

8) Observe that the Program got executed, but was unable to see the Output, as the Console displayed and got exited before one could see the output. To overcome this problem, lets written another line of code which waits for the User input as shown below:

Console.ReadLine(); //Waits for the User input.

C# for Selenium - Updated Code

9) Lets execute the updated code again by clicking ‘Start’ button on the Visual Studio IDE or by pressing ‘F5’ key on your keyboard and observe that the we can see the Output as shown below:

C# for Selenium - Output First Program

Hurray! You have successfully executed your first program written in C#.

I will demonstrate more C# programs in upcoming articles. Stay Tuned.

Next Steps:

  • > To learn more about Selenium C#, continue to the next post (Click on Next Post Link Below)
  • > Check complete Selenium C# Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Praneeth Gadepalli

Connect to me on Linked In (Click here)

On a mission to contribute to the Software Testing Community in all possible ways.

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp