Nizamuddin Siddiqui has Published 2303 Articles

How can we call one constructor from another in the same class in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Aug-2020 07:00:29

1K+ Views

Make use of this keyword in c# to call one constructor from another constructorTo call a constructor which is present in parent class make use of base keywordExampleclass Demo{    public Demo(){       System.Console.WriteLine("Parameter less constructor called");    }    public Demo(int firstNumber, int secondNumber) : this(){   ... Read More

How to call a static constructor or when static constructor is called in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Aug-2020 06:57:56

839 Views

Static constructor are called automatically before the first instance is created or any static members are referenced.A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only.In c#, only one static constructor is allowed to createStatic constructors have ... Read More

How do you give a C# Auto-Property a default value?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Aug-2020 06:54:58

2K+ Views

In C# 5.0 and before to give an value to the Auto Property we have to do in the constructorThe constructor will be automatically called when class is instantiated and the value will be setAfter C#5.0 a new way to give a value to auto property has come which is ... Read More

How can we return multiple values from a function in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Aug-2020 06:53:23

3K+ Views

In c# multiple values can be returned using the below approaches −Reference parametersOutput parametersReturning an ArrayReturning a TupleReference parametersExampleclass Program{    static int ReturnMultipleValuesUsingRef(int firstNumber, ref int secondNumber){       secondNumber = 20;       return firstNumber;    }    static void Main(){       int a ... Read More

Why cannot we specify access modifiers inside an interface in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Aug-2020 06:51:08

918 Views

Interface methods are contract with the outside world which specifies that class implementing this interface does a certain set of things.Interface members are always public because the purpose of an interface is to enable other types to access a class or struct.Interfaces can have access specifiers like protected or internal ... Read More

Which is better System.String or System.Text.StringBuilder classes in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Aug-2020 06:49:44

2K+ Views

The main difference is StringBuilder is Mutable whereas String is Immutable.String is immutable, Immutable means if you create string object then you cannot modify it and It always create new object of string type in memory.On the other hand, StringBuilder is mutable. Means, if we create a string builder object ... Read More

What are different types of parameters to a method in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Aug-2020 06:47:17

2K+ Views

Methods in C# are generally the block of codes or statements in a program which gives the user the ability to reuse the same code which ultimately saves the excessive use of memory, acts as a time saver and more importantly, it provides better readability of the code.There might be ... Read More

What are different types of access modifiers available in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Aug-2020 06:44:13

2K+ Views

Access modifiers are used to specify the scope of accessibility of a member of a class or type of the class itself. There are six different types of access modifiers.PublicPrivateProtectedInternalProtected InternalPrivate ProtectedPublic Access ModifierObjects that implement public access modifiers are accessible from everywhere in a project without any restrictions.Exampleusing System; ... Read More

What is @ in front of a string in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Aug-2020 06:39:59

13K+ Views

It marks the string as a verbatim string literal.In C#, a verbatim string is created using a special symbol @. @ is known as a verbatim identifier. If a string contains @ as a prefix followed by double quotes, then compiler identifies that string as a verbatim string and compile ... Read More

What does the two question marks together (??) mean in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 04-Aug-2020 06:37:56

3K+ Views

It is the null-coalescing operator. The null-coalescing operator ?? returns the value of its left-hand operand if it isn't null; otherwise, it evaluates the right-hand operand and returns its result. The ?? operator doesn't evaluate its right-hand operand if the lefthand operand evaluates to non-null.A nullable type can represent a value ... Read More

Advertisements