Nizamuddin Siddiqui has Published 2307 Articles

What are binary literals and digit separators in C# 7.0?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:59:34

349 Views

Binary Literals −Before C# 7 we were able to assign only decimal and hexadecimal values to a variable.In C# 7.0 binary literal has been introduced and it allows us binary value to the variable.Digit Separator −Digit Separator takes the form of a single underscore (_). This separator can be used ... Read More

What is Pattern Matching in C# 7.0?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:52:35

243 Views

C# 7.0 introduces pattern matching in two cases, the is expression and the switch statement.Patterns test that a value has a certain shape, and can extract information from the value when it has the matching shape.Pattern matching provides more concise syntax for algorithmsYou can perform pattern matching on any data ... Read More

What are Local functions in C# 7.0?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:48:35

112 Views

Local functions are private methods of a type that are nested in another member. They can only be called from their containing member.Local functions can be declared in and called from −Methods, especially iterator methods and async methodsConstructorsProperty accessorsEvent accessorsAnonymous methodsLambda expressionsFinalizersOther local functionsExample 1class Program{    public static void ... Read More

What are Deconstructors in C# 7.0?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:47:24

152 Views

C# allows to use multiple deconstructor methods in the same program with the same number of out parameters or the same number and type of out parameters in a different order.It's a part of the new tuple syntax - which has nothing to do with the Tuple classes but is ... Read More

What are the improvements in Out Parameter in C# 7.0?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:45:14

137 Views

We can declare out values inline as arguments to the method where they're used.The existing out parameters has been improved in this version. Now we can declare out variables in the argument list of a method call, rather than writing a separate declaration statement.Advantages −The code is easier to read.No ... Read More

What is difference between using if/else and switch-case in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:43:48

313 Views

Switch is a selection statement that chooses a single switch section to execute from a list of candidates based on a pattern match with the match expression.The switch statement is often used as an alternative to an if-else construct if a single expression is tested against three or more conditions.Switch ... Read More

How to implement interface in anonymous class in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:39:59

2K+ Views

No, anonymous types cannot implement an interface. We need to create your own type.Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first.The type name is generated by the compiler and is not available at ... Read More

How to write retry logic in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:38:37

1K+ Views

Retry logic is implemented whenever there is a failing operation. Implement retry logic only where the full context of a failing operation.It's important to log all connectivity failures that cause a retry so that underlying problems with the application, services, or resources can be identified.Exampleclass Program{    public static void ... Read More

What is the difference between Monitor and Lock in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:36:43

2K+ Views

Both Monitor and lock provides a mechanism that synchronizes access to objects. lock is the shortcut for Monitor.Enter with try and finally.Lock is a shortcut and it's the option for the basic usage. If we need more control to implement advanced multithreading solutions using TryEnter() Wait(), Pulse(), & PulseAll() methods, ... Read More

How to sort a list of complex types using Comparison delegate in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:32:43

423 Views

Overloads of the Sort() method in List class expects Comparison delegate to be passed as an argument.public void Sort(Comparison comparison)CompareTo returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object or the other Int16 instance.The ... Read More

Advertisements