C#

C# BASIC SYNTAX

0

C# is an object-oriented programming language. In Object-Oriented Programming methodology
A program consists of various objects that interact with each other by means of actions. The actions that an object may take are called methods.
Objects of the same kind are said to have the same type or, more often, are said to be in the same class.

using System;

// Dog class
class Dog
{
    public void Bark()
    {
        Console.WriteLine("Woof! Woof!");
    }
}

class Program
{
    static void Main()
    {
        // Creating an object of the Dog class
        Dog dog = new Dog();

        // Calling the method on the Dog object
        dog.Bark(); // Output: "Woof! Woof!"
    }
}

Output

Woof! Woof!
  1. class Dog:
    This defines a class called Dog. It’s like a blueprint for creating objects that represent dogs in our program.

  2. public void Bark():
    This is a method (action) inside the Dog class.

  3. class Program:
    This defines another class called Program, which will be our starting point for the program.

  4. static void Main():
    This is the entry point of the program. The Main method is where the program starts executing.

  5. Dog dog = new Dog();:
    This line creates an object of the Dog class. It’s like creating a new dog based on the blueprint defined in the Dog class.

  6. dog.Bark();:
    This line calls the Bark method on the dog object. It’s like telling the dog to perform the “Bark” action

Leave a Reply

Your email address will not be published. Required fields are marked *