devxlogo

.NET

How to Escape Curly Braces in C#

To escape curly braces in c#, use double curly braces. See the example below. var stringWithCurlyBraces = string.Format(“Good {{ ???{0}??? }}”,”example”);Console.Write(stringWithCurlyBraces);//will output Good { ‘example’ }

Decompile Code from a .NET Executable

We often lose the source code of the executables we build. If we have the executable with us, we can still retrieve the code using tools such as ILSpy. You

Case Insensitive Comparison of Two Strings

We often compare two strings to the same case and then compare them to see if they are the same. Instead, we can use the StringComparison class’s InvariantCultureIgnoreCase property. String.Equals(‘stringOne’,

Easily Create a String of Repeated Characters

Use the string class’s constructor to specify the character and the number of times you want it to be repeated. Listing 1. Repeat String Characters String repeatedCharacterString = new String(‘*’,50);

Change the Default TLS Version in .NET

.NET uses SSL3 as the default security protocol for communicating with vendor servers. You can override the default SecurityProtocol used in .NET by setting the TLS 1.2 version explicitly: ServicePointManager.SecurityProtocol

Exposing Internal Methods to Other Assemblies in .NET

The InternalsVisibleTo?attribute of System.Runtime.CompilerServices?class allows you to expose internal methods of one assembly to another. All you have to do is to specify this in the assemblyinfo.cs?file of the assembly