George John has Published 1167 Articles

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

157 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

56 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

614 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

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

445 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

599 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

181 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

C# String.PadRight Method

George John

George John

Updated on 23-Jun-2020 09:06:37

255 Views

Pad the end of the string with spaces using the PadRight() method. You can also pad it with a Unicode character.Let’s say the following is our string.string myStr = "Text1";To set a padding at the end of the above string, use the PadRight method.myStr.PadRight(10);Here is the complete example.Example Live Demousing System; ... Read More

Size of a Three-dimensional array in C#

George John

George John

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

990 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

C# Decimal ("D") Format Specifier

George John

George John

Updated on 23-Jun-2020 08:55:14

2K+ Views

The "D" (or decimal) format specifier works for integer type. It converts a number to a string of decimal digits (0-9).Let’say the following is our number.int val = 467;Now to return the result as 0467, use the following decimal format specifier.val.ToString("D4")Let us see another example.Example Live Demousing System; using System.Globalization; class ... Read More

Advertisements