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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Console.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 MoreHow to return multiple values to caller method in c#?
Returning multiple values from a method in C# can be achieved through several approaches. The most modern and efficient approach is using ValueTuple, introduced in C# 7.0, which provides a lightweight mechanism for returning multiple values with optional named elements. ValueTuples are both performant and allow referencing by names the programmer chooses. They are available under the System.ValueTuple NuGet package for older framework versions. Syntax Following is the syntax for declaring a method that returns multiple values using ValueTuple − public (int, string, string) MethodName() { return (value1, value2, value3); } ...
Read MoreHow do I get a human-readable file size in bytes abbreviation using C#?
To get a human-readable file size in bytes with proper abbreviations, C# requires converting raw byte values into appropriate units like KB, MB, GB, or TB. This involves dividing by 1024 (or 1000 depending on your preference) and selecting the most appropriate unit to display. The key is to create a method that automatically determines the best unit and formats the size accordingly, rather than showing all units simultaneously. Syntax To get file size in bytes − long sizeInBytes = new FileInfo(filePath).Length; To format the size into human-readable format − string ...
Read MoreSortedDictionary.Item[] Property in C#
The SortedDictionary.Item[] property in C# provides indexer access to get or set values associated with specified keys in a sorted dictionary. This property allows you to access dictionary elements using square bracket notation, making it convenient to retrieve and modify values. Syntax Following is the syntax for the SortedDictionary.Item[] property − public TValue this[TKey key] { get; set; } Parameters key − The key of the value to get or set of type TKey. Return Value Returns the value of type TValue associated with the specified key. ...
Read MoreGetting the Type of the Tuple's Element in C#
In C#, you can get the type of a tuple or its individual elements using the GetType() method and reflection. The GetType() method returns the runtime type of the tuple, which includes information about all its element types. Syntax Following is the syntax to get the type of a tuple − var tuple = Tuple.Create(value1, value2, ...); Type tupleType = tuple.GetType(); To get the type of individual elements, you can use the typeof operator or access element types through reflection − Type elementType = typeof(T); // where T is the element type ...
Read MoreGet an enumerator that iterates through the StringDictionary in C#
The StringDictionary class in C# provides the GetEnumerator() method to obtain an enumerator that iterates through the collection. This enumerator returns DictionaryEntry objects containing key-value pairs. Note that StringDictionary automatically converts all keys to lowercase during storage. Syntax Following is the syntax for getting an enumerator from StringDictionary − IEnumerator enumerator = stringDictionary.GetEnumerator(); To iterate through the enumerator − while (enumerator.MoveNext()) { DictionaryEntry entry = (DictionaryEntry)enumerator.Current; // Use entry.Key and entry.Value } Using GetEnumerator() Method The following example demonstrates how to ...
Read MoreTotal number of elements in a specified dimension of an Array in C#
In C#, you can get the total number of elements in a specific dimension of an array using the GetLongLength() method. This method returns a long value representing the number of elements in the specified dimension, making it useful for both single-dimensional and multi-dimensional arrays. Syntax Following is the syntax for using GetLongLength() method − long count = array.GetLongLength(dimension); Parameters dimension − An integer that specifies the dimension (zero-based index) for which you want to get the number of elements. Return Value The method returns a long value representing ...
Read MoreWhat does the two question marks together (??) mean in C#?
The null-coalescing operator (??) in C# returns the value of its left-hand operand if it isn't null; otherwise, it evaluates and returns the right-hand operand. This operator provides a concise way to handle null values and assign default values. The ?? operator is particularly useful with nullable types, which can represent either a value from the type's domain or be undefined (null). It helps prevent InvalidOperationException exceptions and reduces the need for verbose null-checking code. Syntax Following is the syntax for the null-coalescing operator − result = leftOperand ?? rightOperand; If leftOperand is ...
Read More