Tag: csharp

Initialize int array in C# ?

Here’s a code snippet demonstrating how to initialize int arrays in C# and display the contents of it using the for loop. How to Initialize int array in C# ? using System; namespace ACConsoleApp1 { class Program { static void Main(string[] args) { int[] inputArray = new int[4] { 3, 5, 2, 4 }; for(int i=0;i<4;i++) Console.WriteLine(inputArray[i]); Console.ReadLine(); } } } Tutorials you might find…

How to use array Rank in C# ?

In C# , the Rank property of the array is is used to get the rank of the array. In simple terms , rank refers to the number of dimensions of the array. How to use array Rank in C# ? You can get the number of dimensions of the array using the Rank property of the array. For instance , the Rank property of…

How to get the Number of Elements in an MultiDimensional Array in C# ?

In one of the previous articles , we demonstrated the usage of the Length property of the array in C# to get the number of elements in it. In this post , lets have a look at getting the number of elements in the multi-dimentional array in C#. How to get the Number of Elements in an MultiDimensional Array in C# ? If you wanted…

How to get the Number of Elements in an Array in C# ?

You can use the Length property of the array to return the number of elements in it. Note that once the array is created , you cannot change its length. How to get the Number of Elements in an Array in C# ? Here’s a code snippet demonstrating the usage of the Length property of the array to get the number of elements. using System;…

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. using System; namespace ACConsoleApp1 { class Program { static void Main(string[] args) { // Gets the Machine Name var machineName =…

How to Convert byte[] to hex string in C# ?

To convert a byte array to hexadecimal string, you can use the BitConverter class in C#. How to Convert byte[] to hex string in C# ? Below is a sample code snippet demonstrating how to achieve this. using System; namespace ACConsoleApp { class Program { static void Main(string[] args) { byte[] input = {1, 56, 45, 34, 23}; string hexData = BitConverter.ToString(input); Console.WriteLine(hexData); Console.ReadLine(); }…

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 change Language Version from C# 6.0 in Visual Studio 2015 ?

There are times when you are developing .NET Project in Visual Studio 2015 with C# 6.0 enabled and you might also have members in your team using Visual Studio 2013 and still want to build and run the project. How to change Language Version from C# 6.0 in Visual Studio 2015 ? You can change the C# language version from the project properties. In the…

How to perform Shallow Copy in C# ?

To perform Shallow copy in C# , you can use the this.MemberwiseClone() method. How to perform Shallow Copy in C# ? Below is a sample code snippet that contains a method ShallowCopy to make a copy of the object. public class Employee { public int Id { get; set; } public string Name { get; set; } public List<Languages> LanguagesKnown { get; set; } public…

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# ? public static bool HasColumn(IDataRecord dataReader, string columnName)…