Samual Sam has Published 2310 Articles

How to create user defined exceptions in C#?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 12:07:05

338 Views

Like any other programming language, in C#, you can easily create user-defined exception. User-defined exception classes are derived from the Exception class.In the below example, the exception created is not a built-in exception.TempIsZeroExceptionYou can try to run the following code to learn how to create user defined exception in C#.Example Live ... Read More

What is the IsFixedSize property of ArrayList class in C#?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 11:48:55

124 Views

The IsFixedSize property of ArrayList class is used to get a value indicating whether the ArrayList has a fixed size.The following is an example stating the usage of isFixedSize property.Example Live Demousing System; using System.Collections; class Demo {    public static void Main() {       ArrayList arrList = new ... Read More

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

Samual Sam

Samual Sam

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

98 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

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

224 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

4K+ 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

5K+ 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

261 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

Advertisements