Samual Sam has Published 2492 Articles

What is the Length property of BitArray class in C#?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 11:47:02

62 Views

The length property is used to gets or sets the number of elements in the BitArray.Our BitArray.BitArray arr = new BitArray( 5 );To calculate the length, use the length property.Console.WriteLine( "Length: {0}", arr.Length );You can try to run the following code to learn how to work with Length property of ... Read More

How to create a String object in C#?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 11:45:14

3K+ Views

To create a string object in C#, use any of the below given method.By assigning a string literal to a String variableBy using a String class constructorBy using the string concatenation operator (+)By retrieving a property or calling a method that returns a stringBy calling a formatting method to convert ... Read More

Compressing and Decompressing files using GZIP Format in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 11:42:42

2K+ Views

To compress and decompress files using GZIP Format, use the GZipStream class.CompressTo zip a file, use the GZipStream class with the FileStream class. Set the following parameters.File to be zipped and the name of the output zip file.Here, outputFile is the output file and the file is read into the ... Read More

Dimensional Array in C#?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 11:39:53

151 Views

C# allows multidimensional arrays. Declare a 2-dimensional array of int as.int [ , , ] a;The simplest form of the multidimensional array is the 2-dimensional array. A 2-dimensional array is a list of one-dimensional arrays.The following is a two-dimensional array with 3 rows and 4 columns.Let us now see an ... Read More

How to find minimum between 2 numbers using C#?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 11:37:27

2K+ Views

Firstly, declare and initialize two numbers.int num1 = 35; int num2 = 55;With that, use if- else to find the minimum number.if (num1 < num2) {    minNum = num1; } else {    minNum = num2; }Above, we have set the minimum value to the variable minNum and printed ... Read More

C# program to sort an array in descending order

Samual Sam

Samual Sam

Updated on 23-Jun-2020 11:33:39

3K+ Views

Initialize the array.int[] myArr = new int[5] {98, 76, 99, 32, 77};Compare the first element in the array with the next element to find the largest element, then the second largest, etc.if(myArr[i] < myArr[j]) {    temp = myArr[i];    myArr[i] = myArr[j];    myArr[j] = temp; }Above, i and ... Read More

Dictionary Methods in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 11:26:04

4K+ Views

Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.The following are the methods −Sr.NoMethod & Description1AddAdd key-value pairs in Dictionary2Clear()Remove all keys and values3RemoveRemoves the element with the specified key.4ContainsKeyChecks whether the specified key exists in Dictionary.5ContainsValueChecks whether the specified key value ... Read More

Compressing and Decompressing files in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 11:09:08

2K+ Views

Use the System.IO.Compression Namespace in C# to compress and decompress files in C#.CompressTo zip a file, use the GZipStream class with the FileStream class. Set the following parameters: File to be zipped and the name of the output zip file.Here, outputFile is the output file and the file is read ... Read More

Call a method Asynchronously in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 10:50:01

178 Views

Asynchronous programming in C# is an efficient approach towards activities blocked or access is delayed. If an activity is blocked like this in a synchronous process, then the complete application waits and it takes more time. The application stops responding. Using asynchronous approach, the applications continues with other tasks as ... Read More

Check if a File exists in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 10:02:16

9K+ Views

Use the File.exists method in C# to check if a file exits in C# or not.Firstly, check whether the file is present in the current directory.if (File.Exists("MyFile.txt")) {    Console.WriteLine("The file exists."); }After that check whether the file exist in a directory or not.if (File.Exists(@"D:\myfile.txt")) {    Console.WriteLine("The file exists."); ... Read More

Advertisements