Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 40 of 2547
Console.ResetColor() Method in C#
The Console.ResetColor() method in C# is used to reset the foreground and background console colors to their default values. This method is particularly useful when you have changed the console colors during program execution and want to restore the original appearance. Syntax Following is the syntax for the Console.ResetColor() method − public static void ResetColor(); Parameters This method takes no parameters. Return Value This method returns void (nothing). Using Console.ResetColor() Method The method restores both foreground and background colors to the system defaults. Here's how colors work in console ...
Read MoreQueue.ToArray Method in C#
The Queue.ToArray() method in C# copies all Queue elements to a new array. This method creates a shallow copy of the queue's elements in the same order (FIFO - First In, First Out). Syntax The syntax for the generic Queue is as follows − public T[] ToArray(); Return Value Returns a new array of type T[] containing copies of the elements from the Queue. The array elements maintain the same order as they would be dequeued from the queue. Queue.ToArray() Process Queue ...
Read MoreGetting an enumerator for a range of elements in the ArrayList in C#
To get an enumerator for a range of elements in the ArrayList, you can use the GetEnumerator(int, int) method. This method allows you to iterate through a specific subset of elements starting from a given index with a specified count. Syntax Following is the syntax for getting an enumerator for a range of elements − IEnumerator enumerator = arrayList.GetEnumerator(startIndex, count); Parameters startIndex − The zero-based starting index of the range. count − The number of elements in the range. Return Value Returns an IEnumerator object that can iterate through ...
Read MoreGet an enumerator that iterates through the SortedSet in C#
The SortedSet class in C# provides the GetEnumerator() method to retrieve an enumerator that iterates through the collection in sorted order. This enumerator allows you to manually control the iteration process using MoveNext() and Current properties. Syntax Following is the syntax for getting an enumerator from a SortedSet − SortedSet.Enumerator enumerator = sortedSet.GetEnumerator(); Following is the syntax for using the enumerator to iterate − while (enumerator.MoveNext()) { T currentElement = enumerator.Current; // process currentElement } Using GetEnumerator() with String Elements The following example ...
Read MoreHow to store n number of lists of different types in a single generic list in C#?
We can store n number of lists of different types in a single generic list by creating a list of List. This approach allows us to store lists containing integers, strings, or any other data type within a single container. Syntax Following is the syntax for creating a list that can hold multiple lists of different types − List containerList = new List(); Each inner list can store objects of any type − List innerList = new List(); innerList.Add(value); // value can be int, string, etc. containerList.Add(innerList); Using List of ...
Read MoreC# Program to Sort a List of String Names Using the LINQ OrderBy() Method
Sorting a list of string names is a common task in programming, and the LINQ OrderBy() method in C# provides an elegant and efficient way to accomplish this. In this article, we will explore how to sort string lists using LINQ, including both ascending and descending order sorting. What is LINQ OrderBy() Method? The LINQ OrderBy() method is used to sort elements of a sequence in ascending order based on a specified key. For descending order, you use OrderByDescending(). These methods work with any IEnumerable collection and return an IOrderedEnumerable. Syntax Following is the syntax for ...
Read MoreSystem.Reflection namespace in C#
The System.Reflection namespace in C# provides classes and interfaces that allow you to examine and interact with assemblies, modules, types, and members at runtime. This powerful feature enables reflection — the ability to inspect and manipulate code dynamically during execution. The Assembly class is central to this namespace, representing a loaded assembly in memory. You can access an assembly through a type's Assembly property or load it dynamically using various methods. Assembly Identity Components An assembly's identity consists of four key components − Simple name − the filename without the extension Version − from the ...
Read MoreConsole.SetBufferSize() Method in C#
The Console.SetBufferSize() method in C# sets the height and width of the console screen buffer area to the specified values. The buffer size determines how much text the console can hold in memory, which affects scrolling and display capabilities. Syntax Following is the syntax for the Console.SetBufferSize() method − public static void SetBufferSize(int width, int height); Parameters width − The width of the buffer area measured in columns. height − The height of the buffer area measured in rows. The buffer size must be greater than ...
Read MoreSortedDictionary.Count Property in C#
The SortedDictionary.Count property in C# returns the number of key/value pairs contained in the SortedDictionary. This read-only property is useful for determining the size of the collection and checking if it's empty. Syntax Following is the syntax for the Count property − public int Count { get; } Return Value The Count property returns an int value representing the total number of key/value pairs in the SortedDictionary. It returns 0 if the dictionary is empty. SortedDictionary Count Property Key-Value Pairs: {100: ...
Read MoreWhat is the difference between int and Int32 in C#?
Int32 is a type provided by .NET framework whereas int is an alias for Int32 in C# language. Both represent 32-bit signed integers and compile to identical code, making them functionally equivalent at runtime. Syntax Following is the syntax for declaring integers using both approaches − Int32 variable1 = value; int variable2 = value; Key Differences Aspect int Int32 Type C# language keyword (alias) .NET Framework type Namespace dependency No namespace required Requires System namespace Compilation Compiles to System.Int32 Direct .NET type ...
Read More