Getting Started with Programming in C#

Goud.Kv
Posted by in C# category on for Beginner level | Points: 250 | Views : 4575 red flag
Rating: 5 out of 5  
 1 vote(s)

As we know that now a days C# plays a major role in most of the Web technologies to write the server side code, Ex: ASP.NET, ASP.NET MVC etc., Lets start with the Basic programming in C# in this chapter.
Recommendation
Read Introduction to C# before this article.

Introduction

We have already seen the Introduction and Features of C# programming language in the previous chapter. Now, we are going to see the basic programming concepts in here.

Getting Started

  1. At First Open the Visual Studio in your computer.

  2. Now, choose New Project from the File menu which opens a dialog box for creating New Project like below,


  3. Select Installed, expand Templates, then expand Visual C# and select Console Application like above.

  4. Give a name to your Project as above, and click Ok to create a project in Solution Explorer.

  5. After creating project, it will opens Program.cs by default as below,
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Hello
    {
        class Program
        {
            static void Main(string[] args)
            {
            }
        }
    }

  6. Now, replace the above code with the below one,
    using System;
    
    namespace Hello
    {
        class Program
    	{
    	    static void Main()
    	    {
    	        Console.WriteLine("Hello ! Welcome to C# Programming");
    	    }
    	}
    }

  7. Press F5 key to open up a Command Prompt window which shows you the mesage "Hello ! Welcome to C# Programming" like below,


Description

Let us re-call the above code once again to learn what's in it.
using System;

namespace Hello
{
    class Program
	{
	    static void Main()
	    {
	        Console.WriteLine("Hello ! Welcome to C# Programming");
	    }
	}
}
In the above code., there are so many sections or blocks.

Body:
Below statement is called as the Heart of the above program.
Console.WriteLine("Hello ! Welcome to C# Programming");
In C#, statements execute sequentially and terminated with a semicolon(;) or a code block(}).

Statement Block:
Statement block is a pair of braces containing any number of elements or might be zero elements, which performs an action in a series of statements.

Ex:
static void Main()
  {
    ....
    .....
  }
Comments or Documentation in C#:
C# supports two ways of Code-Documentation or Comments. They are, single line and multi line.
Below example is the syntax of using comments in C#.
// This is a single line comment

/* This is a multi line comment
   with two lines */
Console:
Console is a static class and also part of .Net Framework. It represents the standard I/O streams and error streams for console application.
Console class cannot be Inherited.
Full name is System.Console.

Conclusion

In this article we have seen creating a simple program in C# with a little description. Hope you understand it well. If you get any doubt on this, please ask in the below comments.

Thanks for reading.

Regards,
Krishna.

Recommendation
Read Identifiers and Keywords in C# Programming after this article.
Page copy protected against web site content infringement by Copyscape

About the Author

Goud.Kv
Full Name: Krishna Vamshi Goud
Member Level: Gold
Member Status: Member,MVP
Member Since: 2/12/2014 2:34:09 AM
Country: India
Thanks & Regards, Krishna


Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)