devxlogo

C#

Escape Characters with the “@” Symbol in C#

Use the “@” symbol to prefix a string that has characters. You do not have to escape the characters in the string. For example, instead of: Var filePathString = “C:\mydocs\share\audit.docx”;

Conditional Catch Blocks in C#

We can now have conditional catch blocks in C#. The catch block will execute only if the condition evaluates to true. Please see below for an example. catch (Exception ex){

Find the Sign of a Number in C#

System.Math?class?has?a?Sign?method?that?will?help?you?determine?if?a?number?has?a?negative?sign?or?positive?sign.? //returns?-1? int?negativeNumber??=?System.Math.Sign(-2);? //?returns?1 int?postiveNumber?=?System.Math.Sign(1);? //returns?0 ?int?neutralNumber?=?Math.Sign(0);?

Format the Console.Write Responses

We use string.format to format the data written to the console using the console.write or console.writeline commands. However, it isn’t indented well to make it readable. C# allows you to

Merge Two Data Tables in C#

If you have two data tables with the same data columns, you can merge them quite easily. Merge Data Tables dataTableEuropeanCities and dataTableAsianCities are two datatables with same schema. They

Controlling Exceptions in C# 6.0

With C# 6.0, you can control exceptions with a conditional if. See below for an example: Listing 1. Control Exceptions try{ //Code that creates an exception}catch (System.DllNotFoundException dllEx) if (version