Tag: csharp

Defining Simple Anoymous Type in C#

To define an anonymous type in C# , we can use the var keyword . The syntax for defining the anonymous type in C# is as follows var <variableName> = <Non-NULL Value> Eg: var WebsiteName = “Abundantcode.com”; In the MSIL , the above code is similar to

How to Check for Column Name in SqlDataReader object in C# ?

Do you want to check if a column exists in a SqlDataReader instance in C# ?. One of the simplest solution is to navigate to all the fields within the data reader and check the name of the field using the GetName method as shown below. How to Check for Column Name in SqlDataReader object in C# ?

How to run the C# program from Commandline using csc.exe ?

Problem Statement You need to use he csc.exe (C# command line compiler) to compile the Csharp program from Command prompt. Solution Use the command prompt and use the csc.exe to compile and run the program from the command prompt. Follow the below steps to compile and run the C# program from command prompt. 1. Type the program in the notepad and save it as hello.cs…

How to get the Machine Name from a .NET Application using C# ?

You can use the MachineName property defined in the System.Environment class in order to get the Machine Name from your .NET Application. How to get the Machine Name from a .NET Application using C# ? Here’s a code sample demonstrating how to do it. This should display the machine name. The output of the program would be The Machine Name is Abundantcode-LT

How to sort an array using Comparator in C# ?

The Array.Sort method lets the developers pass the comparator which can be used to sort an array of objects. How to sort an array using Comparator in C# ? In the below example , the method CompareByName is used which lets the Array.Sort method to sort the array of objects in descending order.