[Solved] Please explain what does the following code mean in c#? [duplicate]


What you are referencing is called a Constructor. Constructors have the same name as the class, and they are used to initialize data members of the new object.

Please reference.

Whenever a class or struct is created, its constructor is called. A class or struct may have multiple constructors that take different arguments. Constructors enable the programmer to set default values, limit instantiation, and write code that is flexible and easy to read.

If you saw code similar to what you mentioned, then honestly that would cause a compile time error, since the syntax for that default constructor (taking 0 parameters) is incorrect.

Needs to be:

public SomeClass()
{
    //initialize members;
}

If you retrieved the code that you just posted a picture of, by hitting Go To Definition of the class, then it will only show declarations, and not implementation.

1

solved Please explain what does the following code mean in c#? [duplicate]