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