Csharp Articles

Page 6 of 196

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 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 that can be undefined or from the type's domain. We can use the ?? operator to return an appropriate value when the left operand has a nullable type. If we try to assign a nullable value type to a non-nullable value type without using the ?? operator, we will get ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 14K+ 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 that string. The main advantage of @ symbol is to tell the string constructor to ignore escape characters and line breaks.Exampleusing System; using System.IO; namespace DemoApplication{    class Program{       static void Main(string[] args){          Console.WriteLine("test string test string");          Console.WriteLine(@"test string ...

Read More

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

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 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 then we can perform any operation like insert, replace or append without creating new instance for every time. It will update string at one place in memory doesn’t create new space in memory.Exampleusing System; using System.Text; class DemoApplication{    public static void Main(String[] args){       String systemString = ...

Read More

What is the difference between List and IList in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 20K+ Views

The main difference between List and IList in C# is that List is a class that represents a list of objects which can be accessed by index while IList is an interface that represents a collection of objects which can be accessed by index. The IList interface implemented from two interfaces and they are ICollection and IEnumerable.List and IList are used to denote a set of objects. They can store objects of integers, strings, etc. There are methods to insert, remove elements, search and sort elements of a List or IList. The major difference between List and IList is that ...

Read More

What is an Optional parameter in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 5K+ Views

By default, all parameters of a method are required. A method that contains optional parameters does not force to pass arguments at calling time. It means we call method without passing the arguments.The optional parameter contains a default value in function definition. If we do not pass optional argument value at calling time, the default value is used.Thera are different ways to make a parameter optional.Using Default ValueExampleusing System; namespace DemoApplication{    class Demo{       static void Main(string[] args){          OptionalMethodWithDefaultValue(5);          //Value2 is not passed as it is optional     ...

Read More

What is the difference between Foreach and Parallel.Foreach in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

Foreach loop in C# runs upon a single thread and processing takes place sequentially one by one. Whereas Parallel.Foreach loop in C# runs upon multiple threads and processing takes place in a parallel way. Which means it is looping through all items at once without waiting for the previous item to complete.The execution of Parallel.Foreach is faster than normal ForEach. To use Parallel.ForEach loop we need to import System.Threading.Tasks namespace.Exampleusing System; using System.Collections.Generic; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; namespace DemoApplication{    class Demo{       static void Main(string[] args){          var animals = new List{ ...

Read More

How to update the value stored in a Dictionary in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 7K+ Views

In C#, Dictionary is a generic collection which is generally used to store key/value pairs. In Dictionary, the key cannot be null, but value can be. A key must be unique. Duplicate keys are not allowed if we try to use duplicate key then compiler will throw an exception.As mentioned above a value in a dictionary can be updated by using its key as the key is unique for every value.myDictionary[myKey] = myNewValue;ExampleLet’s take a dictionary of students having id and name. Now if we want to change the name of the student having id 2 from "Mrk" to "Mark".using ...

Read More

How to create Guid value in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

A Globally Unique Identifier or GUID represents a gigantic identification number — a number so large that it is mathematically guaranteed to be unique not only in a single system like a database, but across multiple systems or distributed applications.The total number of unique keys (3.40282366×1038) is so large that the probability of the same number being generated twice is very small. For an application using 10 billion random GUIDs, the probability of a coincidence is approximately 1 in a quintillion.(1030)For example, in Retail domain if we want to generate a unique for each transaction so that a customer can ...

Read More

How to implement a Singleton design pattern in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 596 Views

Singleton Pattern belongs to Creational type patternSingleton design pattern is used when we need to ensure that only one object of a particular class is Instantiated. That single instance created is responsible to coordinate actions across the application.As part of the Implementation guidelines we need to ensure that only one instance of the class exists by declaring all constructors of the class to be private. Also, to control the singleton access we need to provide a static property that returns a single instance of the object.ExampleSealed ensures the class being inherited and object instantiation is restricted in the derived classPrivate ...

Read More

What is typeof, GetType or is in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

Typeof()The type takes the Type and returns the Type of the argument.GetType()The GetType() method of array class in C# gets the Type of the current instance.isThe "is" keyword is used to check if an object can be casted to a specific type. The return type of the operation is Boolean.Exampleclass Demo { } class Program {    static void Main() {       var demo = new Demo();       Console.WriteLine($"typeof { typeof(Demo)}");       Type tp = demo.GetType();       Console.WriteLine($"GetType {tp}");       if (demo is Demo) {          System.Console.WriteLine($"is ...

Read More
Showing 51–60 of 1,951 articles
« Prev 1 4 5 6 7 8 196 Next »
Advertisements