C# Basic Syntax and OOP language

Basic Syntax and OOP language, In Object-Oriented Programming methodology, the software includes numerous objects that engage with every other through moves.

The movements that an item may also take are called methods. Objects of the identical type are stated to have the identical kind or, are stated to be within the identical elegance.

For example, let us consider a Rectangle object. It has attributes along with period and width.

Depending upon the layout, it could want ways for accepting the values of these attributes, calculating the location, and displaying information.

Let us observe implementation of a Rectangle class and discuss C# primary syntax

object orientated programming language
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();

When the above code is compiled and accomplished, it produces the following result

Length: four.5 Width: three.5 Area: 15.Seventy five

The the usage of Keyword

The first declaration in any C# program is

the usage of System;

The the usage of key-word is used for along with the namespaces in the program. A program can encompass a couple of the use of statements.

The class Keyword

The elegance key-word is used for asserting a class.

Comments in C#

Comments are used for explaining code. Compilers ignore the comment entries.

The multiline remarks in C# packages start with /* and terminates with the characters */ as shown underneath

/* This program demonstrates The basic syntax of C# programming Language */

Single-line comments are indicated by the ‘//’ symbol. For example,

}//end class Rectangle

Member Variables

Basic Syntax and OOP language, Variables are attributes or records contributors of a class, used for storing information. In the preceding application, the Rectangle class has two member variables named period and width.

Member Functions

Functions are set of statements that perform a specific undertaking. The member features of a class are declared inside the magnificence. Our sample class Rectangle includes three member capabilities: AcceptDetails, GetArea and Display.

Instantiating a Class

In the preceding program, the class ExecuteRectangle incorporates the Main() technique and instantiates the Rectangle magnificence.

Basic Syntax and OOP language, Identifiers

An identifier is a name used to discover a class, variable, function, or any other person-defined object. The fundamental regulations for naming training in C# are as follows −

  • A call should begin with a letter that might be observed with the aid of a series of letters, digits (0 – nine) or underscore. The first character in an identifier cannot be a digit.
  • It should now not include any embedded space or symbol together with? – + ! @ # % ^ & * ( ) [ ] . ; : ” ‘ / and . However, an underscore ( _ ) can be used.
  • It should now not be a C# keyword.

Basic Syntax and OOP language, C# Keywords

Keywords are reserved words predefined to the C# compiler. These keywords cannot be used as identifiers. However, if you want to apply these key phrases as identifiers, you could prefix the key-word with the @ person.

In C#, a few identifiers have special meaning in context of code, which include get and set are called contextual key phrases.

The following table lists the reserved key phrases and contextual keywords in C#

Reserved Keywords

abstract as base bool break byte case
catch char checked class const continue decimal
default delegate do double else enum event
explicit extern false finally fixed float for
foreach goto if implicit in in (generic modifier) int
interface internal is lock long namespace new
null object operator out out (generic modifier) override params
private protected public readonly ref return sbyte
sealed short sizeof stackalloc static string struct
switch this throw true try typeof uint
ulong unchecked unsafe ushort using virtual void
volatile while

Basic Syntax and OOP language, Contextual Keywords

add alias ascending descending dynamic from get
global group into join let orderby partial (type)
partial (method) remove select set