Tag: C#
General Numeric Formatting in C#
Below is a sample source code demonstrating General Numeric Formatting(G) string in C# .
How to Prevent the Class from Inheriting in C# ?
You can use the keyword “sealed” in C# to prevent the user from inheriting the class. Below is a class that is marked as sealed and is not inheritable. How to Prevent the Class from Inheriting in C# ?
Example of Anonymous Method in C#
Below is a sample code snippet that demonstrates how to use anonymous method to add two numbers in C#. Example of Anonymous Method in C#
Convert Value type to String in C#
Below is a sample sourecode snippet demonstrating how to Convert Value type to String in C#
How to Convert Enum to Integer in C# ?
Below is a sample sourcecode that demonstrates how to Convert Enum to Integer in C# ?
How to Create ByteArray from a Stream in C#?
Below is a sample code snippet that demonstrates an easy way to create a ByteArray from the Stream that contains data in C#. How to Create ByteArray from a Stream in C#?
Different Assignment Operators available in C#
Below are some of the different Assignment Operators that are available in C# += -= *= /= %= |= &= ^=
How to find the reverse of a number using C# ?
Below is a sample code snippet that demonstrates how to find the reverse of a number using C# . How to find the reverse of a number using 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…
How to Remove Objects from the List with RemoveAll in C#?
Below is a sample code snippet demonstrating How to Remove Objects from the List with RemoveAll in C#? How to Remove Objects from the List with RemoveAll in C#?
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.
How to select top 5 records from List using LINQ in C#?
Below is a sample code snippet demonstrating on how to select top 5 records from a list using LINQ in C# using the Take extension method… How to select top 5 records from List using LINQ in C#?
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 write a byte array to a File in C# ?
If you want to write a byte array to a file in C# , you can use the File.WriteAllBytes . Below is a code snippet demonstrating this. How to write a byte array to a File in C# ?
How to Convert Decimal to byte array in C# ?
Below is a sample sourcecode that demonstrates how to Convert DEcimal to byte array in C#
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…