find and solve ||
Please wait.....

C# Program Structure And Basic Syntax With Examples

C# Basic Syntax

In basic of c# programming, pronounced as c sharp, is a modem, high-level, robust, powerful, and object-oriented programming language that is based on the traditional C++ language. However, C# is relatively easier to learn and, work with than C++ because it has a simple syntax and is a  .NET-compatible language. Being a DT '4 compatible languages, it can use the services that Common Language Runtime (CLR) offers, such as type-safety, garbage collection, and integrated security. Microsoft introduced C# along with the beta version of the .NET Framework in 2000. Since then, C# has been an important part of the .NET Framework server Web applications, and database applications. 

More Details Click here

Let us look at the implementation of a  class and discuss C# basic syntax 

using System;

namespace RectangleApplication
    class Rectangle

        // member variables
        double length;
        double width;

        public void Acceptdetails()
            length = 2.5;
            width = 4.5;
        public double GetArea()
            return length * width;
        public void Display()
            Console.WriteLine("Length: {0}", length);
            Console.WriteLine("Width: {0}", width);
            Console.WriteLine("Area: {0}", GetArea());
    class MainClassForRectangle
        static void Main(string[] args)
            Rectangle r = new Rectangle();

"using system" Keyword in c sharp basics for beginners

The first statement in any C# program is using system.
The using keyword is used for including different namespaces in the your program. your  program can include multiple using statements depent on your namespace or project.

What is "class"Keyword?
Is it used only for declaring a class keyword.
For more details click here

What is Comments in C# ?

Comments are used for explaining code which is not compile when project is running commnets are ignore the comment entries. The multiline comments in C# programs start with
 /* your comment code here*/
 and single comment use only

What is Member Variables ?

A variable is a block of memory where data or value of a particular data type is stored.Every variable has as name,data types,and an initial value.The name or identifier of the variable allows you to access the memory location where it's values is stored.The data type of the variable inform the compiler about the size of memory that the variable occupies.In addition,the data type indicates the type of values the variable can stored.The value you store in a variable can be changed or modify any number of times in the program.

What is Functions ?

Function is a block of code that has does something and then returns the value.The function is used to execute statements in the code block.
For more Details Click here

Introducing Keywords and Identifiers 

In C#, you work with certain predefined and user-defined words or names. The words or names that  are predefined are called keywords, while those that are user-defined are called identifiers  and identifiers is the name that you give to the programming elements created in a program. For Example,The names that you give to the variables and arrays are identifiers. A variable is a placeholder to store a single value  of a particular kind. An array is an ordered collection of a particular kind of values. 

Note that you cannot define an identifier that is same as a keyword. This is because keywords are those words, which are defined in the programming language to perform a particular task or indicate some programming aspect, such as creating a class. C# has many keywords that are automatically recognized by its compiler. In C#, there are two types of keywords, reserved and contextual. A reserved keyword performs the same predefined task wherever you use it in your C# program; whereas, a contextual keyword may perform different tasks based on the context in which you use it

Reserved Keywords

foreachgotoifimplicitinin (generic modifier)int
nullobjectoperatoroutout (generic modifier)overrideparams

Contextual Keywords

globalgroupintojoinletorderbypartial (type)

Sundar  Neupane

Sundar Neupane

I like working on projects with a team that cares about creating beautiful and usable interfaces.

If felt valuable to you, feel free to share it.


Report Response