Tag: C#

How to get the CommandLine of the Current Application in C# ?

You might need to get the information that contains the commandline which is used to execute the current application in C#. How to get the CommandLine of the Current Application in C# ? You can use the CommandLine property of the System.Environment class that provides the necessary information including the application name. The output of the program would be Command line of the Abundantcode app…

Cast Operator with Anonymous Types

Below is a sample sourecode that demonstrates the usage of the Cast Operator when using the anonymous type Cast Operator with Anonymous Types When the element within the List cannot be converted to the target type, you will receive an exception “InvalidCastException”.

The ? (ternary) Operator in C#

The ? Operator is the ternary operator and takes the following form Expression1? Expression2: Expression3; The Expression1 is an expression which returns Boolean result. Expression2 is considered if the Expression1 is true else Expression2 is taken.

What are the different types of comments in C#?

There are 3 different types of comments in C#. These include 1. Single Line CommentThe single line comment is specified using the symbol // Eg: // this is a AbundantCode comment 2. Multi Line CommentThe Multiline comment can be specified using the symbol /* */ Eg: /* This is a test comment */ 3. XML CommentThis is a special kind of comment which is generally…

How to Compute area of a circle in C# ?

Below is a sample sourcecode that demonstrates the computation of the area of a circle in c# using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { double radiusofcircle; double areaOfCircle; double pi = 3.1416; radiusofcircle = 25; areaOfCircle = radiusofcircle * radiusofcircle * pi; Console.WriteLine(“Area is ” + areaOfCircle); Console.Read(); } } }

How to find if 2 Objects are Equal in C#?

There are times when you need to determine if 2 objects are equal or not. In these cases, you could either override the Equals method or implement IEquatable interface. How to find if 2 Objects are Equal in C#? Below is a sample code snippet demonstrating the usage of Object.Equals method to find the equality of 2 objects.

How to fill an array with default values in C# ?

To fill an array with the default values in C# , you can use the Enumerable.Repeat method to do it. How to fill an array with default values in C# ? Below is a sample code illustrating the usage of the Enumerable.Repeat method to fill an array with default values.

How to Convert a Character to Upper Case in C# using Char.ToUpper ?

The Char class provides the method ToUpper which will convert the any given character to its corresponding upper case character from lower case character. The Char.ToUpper accepts the character as parameter and returns the char with the Upper Case . How to Convert a Character to Upper Case in C# using Char.ToUpper ? Below is a sample sourcecode demonstrating How to Convert a Character to…