George John

George John

789 Articles Published

Articles by George John

Page 3 of 79

C# program to create an empty string array

George John
George John
Updated on 17-Mar-2026 4K+ Views

Creating an empty string array in C# is useful when you need to declare an array without initial elements. There are several ways to create an empty string array, each serving different purposes depending on your requirements. Syntax Following are the different ways to create an empty string array − string[] str = new string[] {}; string[] str = new string[0]; string[] str = {}; Using Array Initializer Syntax The most straightforward way to create an empty string array is using the array initializer syntax with empty braces − using System; ...

Read More

How are values assigned to arrays in C#?

George John
George John
Updated on 17-Mar-2026 177 Views

Declaring an array does not initialize the array in memory. When the array variable is initialized, you can assign values to the array using several different approaches in C#. Array is a reference type, so you need to use the new keyword to create an instance of the array. There are multiple ways to assign values to arrays, each with its own syntax and use cases. Syntax Following is the syntax for declaring and initializing arrays − // Declaration with size datatype[] arrayName = new datatype[size]; // Assignment using index arrayName[index] = value; ...

Read More

Bool Array in C#

George John
George John
Updated on 17-Mar-2026 10K+ Views

A bool array in C# is used to store multiple boolean values (true and false) in a single collection. Boolean arrays are useful for tracking states, flags, or conditions across multiple elements. Syntax Following are the different ways to declare and initialize a bool array − // Declaration with size bool[] arrayName = new bool[size]; // Declaration with initialization bool[] arrayName = {true, false, true}; // Using new keyword with values bool[] arrayName = new bool[] {true, false, true}; Creating and Initializing Bool Arrays Method 1: Declaration with Size and Assignment ...

Read More

How to use ReadKey() method of Console class in C#?

George John
George John
Updated on 17-Mar-2026 2K+ Views

The Console.ReadKey() method in C# reads the next character or function key pressed by the user. This method is commonly used to pause program execution until the user presses a key, which is particularly useful when running console applications from Visual Studio to prevent the console window from closing immediately. Syntax The Console.ReadKey() method has two overloads − public static ConsoleKeyInfo ReadKey(); public static ConsoleKeyInfo ReadKey(bool intercept); Parameters intercept (optional): A boolean value that determines whether to display the pressed key in the console. If true, the key is not displayed; if ...

Read More

final, finally and finalize in C#

George John
George John
Updated on 17-Mar-2026 5K+ Views

In C#, the terms final, finally, and finalize serve different purposes. While final doesn't exist in C#, finally and finalize are crucial concepts for exception handling and resource cleanup respectively. final (sealed in C#) C# does not have a final keyword like Java. Instead, C# uses the sealed keyword to achieve similar functionality − public sealed class SealedClass { // cannot be inherited } public override sealed void SealedMethod() { // cannot be overridden further } The sealed keyword prevents overriding of methods or inheritance of classes. ...

Read More

The nameof keyword in C#

George John
George John
Updated on 17-Mar-2026 605 Views

The nameof operator in C# returns the string literal name of a variable, type, or member. It provides a compile-time constant string that represents the name of the code element, making it useful for logging, exception messages, and property change notifications without hardcoding strings. Syntax Following is the syntax for using the nameof operator − string name = nameof(element); Where element can be a variable, property, method, class, or namespace. Using nameof with Variables The nameof operator returns the variable name as a string, which is resolved at compile time − ...

Read More

HashSet in C#

George John
George John
Updated on 17-Mar-2026 920 Views

A HashSet in C# is a high-performance collection that stores unique elements and automatically eliminates duplicates. It provides fast lookups, insertions, and deletions with O(1) average time complexity, making it ideal for scenarios where you need to maintain a collection of distinct values. HashSet is part of the System.Collections.Generic namespace and implements the ISet interface, providing mathematical set operations like union, intersection, and difference. Syntax Following is the syntax for declaring and initializing a HashSet − HashSet hashSetName = new HashSet(); You can also initialize it with an existing collection − ...

Read More

Combine two arrays in C#

George John
George John
Updated on 17-Mar-2026 6K+ Views

Combining two arrays in C# can be accomplished using various methods. The most common approaches include using List.AddRange() method, Array.Copy(), or LINQ's Concat() method. Syntax Using List.AddRange() method − var list = new List(); list.AddRange(array1); list.AddRange(array2); T[] combinedArray = list.ToArray(); Using Array.Copy() method − T[] combinedArray = new T[array1.Length + array2.Length]; Array.Copy(array1, 0, combinedArray, 0, array1.Length); Array.Copy(array2, 0, combinedArray, array1.Length, array2.Length); Using LINQ Concat() method − T[] combinedArray = array1.Concat(array2).ToArray(); Using List.AddRange() Method This approach creates a List, adds both arrays using AddRange(), then converts ...

Read More

C# Convert.ToInt32 Method

George John
George John
Updated on 17-Mar-2026 857 Views

The Convert.ToInt32 method in C# is used to convert various data types to a 32-bit signed integer. It is commonly used to convert strings, floating-point numbers, and other numeric types to integers, providing a versatile approach to type conversion. Syntax Following are the most common syntax forms for Convert.ToInt32 − Convert.ToInt32(value); Convert.ToInt32(value, fromBase); Parameters value − The value to convert (string, double, decimal, bool, etc.) fromBase − Optional. The base of the number system (2, 8, 10, or 16) Return Value Returns a 32-bit signed integer equivalent to the ...

Read More

Singly LinkedList Traversal using C#

George John
George John
Updated on 17-Mar-2026 254 Views

A LinkedList in C# is a doubly-linked list that allows efficient insertion and removal of elements. Traversal refers to visiting each node in the LinkedList sequentially to access or process the data. The LinkedList class in C# provides various methods to traverse through its elements, with the most common approach being the foreach loop. Syntax Following is the syntax for declaring a LinkedList − var linkedList = new LinkedList(); Following is the syntax for traversing a LinkedList using foreach − foreach(var item in linkedList) { // Process each ...

Read More
Showing 21–30 of 789 articles
« Prev 1 2 3 4 5 79 Next »
Advertisements