George John has Published 1081 Articles

DivideByZeroException Class in C#

George John

George John

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

947 Views

C# exceptions are represented by classes. The exception classes in C# are mainly directly or indirectly derived from the System.Exception class. Some of the exception classes derived from the System.Exception class are the System.ApplicationException and System.SystemException classes.System.DivideByZeroException is a class that handles errors generated from dividing a dividend with zero.Example Live ... Read More

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

George John

George John

Updated on 23-Jun-2020 10:05:00

102 Views

Use the IsFixedSize property in C# to get a value indicating whether the SortedList has a fixed size.The following is an example showing SorteList with the usage of IsFixedSize property.Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {   ... Read More

Check if both halves of the string have same set of characters in C#

George John

George John

Updated on 23-Jun-2020 10:00:49

204 Views

Firstly, set the string to be checked.string s = "timetime";Now set two counters for two halves of the string.int []one = new int[MAX_CHAR]; int []two = new int[MAX_CHAR];Check for both the halves of the string.for (int i = 0, j = l - 1; i < j; i++, j--) { ... Read More

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

George John

George John

Updated on 23-Jun-2020 09:57:43

105 Views

The BitArray class is used when you need to store the bits but do not know the number of bits in advance.Using the IsReadOnly class, you can get a value indicating whether the BitArray is read-only or not. ReadOnly will not allow you to add new elements to the BitArray.The ... Read More

Difference between Static Constructor and Instance Constructor in C#

George John

George John

Updated on 23-Jun-2020 09:38:41

807 Views

Static ConstructorA static constructor is a constructor declared using static modifier. It is the first block of code executed in a class. With that, a static constructor executes only once in the life cycle of class.Instance ConstructorInstance constructor initializes instance data. Instance constructor is called when an object of class ... Read More

Enum with Customized Value in C#

George John

George John

Updated on 23-Jun-2020 09:29:44

2K+ Views

Enum is Enumeration to store a set of named constants like year, product, month, season, etc.The default value of Enum constants starts from 0 and increments. It has fixed set of constants and can be traversed easily. However you can still change the start index and customize it with the ... Read More

Different Methods to find Prime Numbers in C#

George John

George John

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

561 Views

The following are the two ways through which you can find a prime number in C#.Check Prime Number using for loop Live Demousing System; namespace Program {    class Demo {       public static void Main() {          int n =7;          int a;          a = 0;          for (int i = 1; i

C# Enum Equals Method

George John

George John

Updated on 23-Jun-2020 09:12:04

710 Views

To find the equality between enums, use the Equals() method.Let’s say we have the following Enum.enum Products { HardDrive, PenDrive, Keyboard};Create two Products objects and assign the same values.Products prod1 = Products.HardDrive; Products prod2 = Products.HardDrive;Now check for equality using Equals() method. It would be True since both have the ... Read More

Create a Quadruple Tuple in C#

George John

George John

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

243 Views

Quadruple is a tuple with four items.Create a tuple first.var myTuple = Tuple.Create(100, 200, 300, 400);Above, we have created a tuple with four items i.e. Quadruple. Now to access all the four items.myTuple.Item1 myTuple.Item2 myTuple.Item3 myTuple.Item4Example Live Demousing System; public class Program {    public static void Main() {     ... Read More

Size of a Three-dimensional array in C#

George John

George John

Updated on 23-Jun-2020 09:01:00

1K+ Views

To get the size of a 3D array in C#, use the GetLength() method with parameter as the index of the dimensions.GetLength(dimensionIndex)To get the size.arr.GetLength(0) arr.GetLength(1) arr.GetLength(2)Example Live Demousing System; class Program {    static void Main() {       int[, , ] arr = new int[3, 4, 5];   ... Read More

Advertisements