C# Programming

Basic Syntax

C# Programming / Basic Syntax

Basic Syntax

C# Syntax Rules: The Fundamentals

1. Case Sensitivity

C# is case-sensitive, meaning that variable names with different capitalization are treated as separate variables.

2. Every Statement Ends with a Semicolon (;)

All statements in C# must end with a semicolon to indicate the end of a command.

3. Curly Braces {} Define Code Blocks

Curly braces group statements together in functions, loops, and conditional statements.

4. Indentation & Whitespace

C# ignores extra spaces and newlines, but proper indentation makes the code more readable.

 

Basic Structure of a C# Program

using System; namespace RectangleApplication {  

 class Rectangle {        

    // member variables      double length;  

    double width;            public void Acceptdetails() {   

      length = 4.5;             width = 3.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 ExecuteRectangle {   

   static void Main(string[] args) {     

    Rectangle r = new Rectangle();       

  r.Acceptdetails();   

      r.Display(); 

        Console.ReadLine();

      }   } }

Technology
C# Programming
want to connect with us ?
Contact Us