C# static 🚫

Author: Bro Code
Published At: 2021-07-03T00:00:00
Length: 05:02

Summary

Description

C# static modifier tutorial example explained

#C# #static #modifier

using System;

namespace MyFirstProgram

{

class Program

{

static void Main(string[] args)

{

// static = modifier to declare a static member, which belongs to the class itself

// rather than to any specific object

Car car1 = new Car("Mustang");

Car car2 = new Car("Corvette");

Car car3 = new Car("Lambo");

Console.WriteLine(Car.numberOfCars);

Car.StartRace();

Console.ReadKey();

}

}

class Car

{

String model;

public static int numberOfCars;

public Car(String model)

{

this.model = model;

numberOfCars++;

}

public static void StartRace()

{

Console.WriteLine("The race has begun!");

}

}

}

Translated At: 2025-06-22T05:35:48Z

Request translate (One translation is about 5 minutes)

Version 3 (stable)

Optimized for a single speaker. Suitable for knowledge sharing or teaching videos.

Recommended Videos