Ankith Reddy

Ankith Reddy

730 Articles Published

Articles by Ankith Reddy

Page 4 of 73

C# TimeSpan Max value

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 1K+ Views

The TimeSpan structure in C# represents a time interval or duration. The TimeSpan.MaxValue property returns the maximum possible value that a TimeSpan can represent. Syntax Following is the syntax to get the maximum TimeSpan value − TimeSpan.MaxValue Return Value The MaxValue property returns a TimeSpan object representing the maximum time span value, which is approximately 10.7 million days or about 29, 227 years. TimeSpan.MaxValue Breakdown 10675199.02:48:05.4775807 Days: 10, 675, 199 Hours: 02 ...

Read More

How to capture out of memory exception in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 2K+ Views

The System.OutOfMemoryException occurs when the CLR fails to allocate sufficient memory for an operation. This exception is inherited from the System.SystemException class and can be caught using try-catch blocks to handle memory allocation failures gracefully. Common scenarios that trigger this exception include attempting to create very large arrays, working with StringBuilder objects that exceed their capacity, or processing extremely large datasets. Syntax Following is the syntax for catching OutOfMemoryException − try { // Code that might throw OutOfMemoryException } catch (OutOfMemoryException ex) { // Handle the exception ...

Read More

How do you sort an array in C# in ascending order?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 10K+ Views

In C#, you can sort an array in ascending order using the built-in Array.Sort() method. This method modifies the original array directly and arranges elements from smallest to largest value. Syntax Following is the syntax for sorting an array in ascending order − Array.Sort(arrayName); Parameters arrayName − The array to be sorted. This parameter is required and the array is modified in-place. Using Array.Sort() Method The Array.Sort() method automatically sorts elements in ascending order. Here's how to sort an integer array − using System; ...

Read More

Declare a const array in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 13K+ Views

In C#, you cannot directly declare a const array because arrays are reference types and const fields must be compile-time constants. However, you can achieve similar behavior using readonly fields or ReadOnlyCollection to create immutable arrays. Syntax Following is the syntax for declaring a readonly array − public static readonly DataType[] arrayName = { value1, value2, value3 }; Following is the syntax for using ReadOnlyCollection − public static readonly ReadOnlyCollection arrayName = new ReadOnlyCollection(new DataType[] { value1, value2, value3 }); Using readonly Static Arrays ...

Read More

C# program to find the index of a word in a string

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 657 Views

Finding the index of a word in a string or array is a common programming task in C#. The Array.IndexOf() method provides an efficient way to locate the position of a specific element within an array of strings. Syntax Following is the syntax for using Array.IndexOf() method − int index = Array.IndexOf(array, searchValue); Parameters array − The one-dimensional array to search searchValue − The object to locate in the array Return Value The method returns the index of the first occurrence of the specified value. If the value is ...

Read More

Default operator in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 733 Views

The default operator in C# returns the default value for any data type. For value types, it returns zero or false, while for reference types, it returns null. The default expressions are evaluated at compile-time, making them efficient for initialization. Starting with C# 7.1, you can use the simplified default literal when the type can be inferred from the context. Syntax Following is the syntax for the traditional default operator − default(Type) Following is the syntax for the simplified default literal (C# 7.1+) − Type variable = default; Default ...

Read More

Implicit conversion from Char to Decimal in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 2K+ Views

In C#, implicit conversion from char to decimal happens automatically when you assign a character value to a decimal variable. The character is converted to its corresponding ASCII or Unicode numeric value, which is then stored as a decimal number. Syntax Following is the syntax for implicit conversion from char to decimal − char c = 'character'; decimal dec = c; // implicit conversion How It Works When you assign a char to a decimal, C# automatically converts the character to its numeric ASCII/Unicode value. For example, the character 'A' has an ...

Read More

Find free disk space using C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 1K+ Views

The DriveInfo class in C# provides information about drives and their storage capacity. You can use this class to find free disk space, total disk space, and calculate the percentage of available space on any drive. Syntax Following is the syntax for creating a DriveInfo instance − DriveInfo driveInfo = new DriveInfo("driveLetter"); Following are the key properties for disk space information − long availableSpace = driveInfo.AvailableFreeSpace; long totalSpace = driveInfo.TotalSize; long usedSpace = driveInfo.TotalSize - driveInfo.AvailableFreeSpace; Using DriveInfo to Get Free Disk Space Example using System; using ...

Read More

Enum.GetName in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 693 Views

The Enum.GetName method in C# returns the string name of a constant in a specified enumeration that has the specified value. This method is useful when you need to convert an enum value back to its string representation for display purposes or logging. Syntax Following is the syntax for the Enum.GetName method − public static string GetName(Type enumType, object value) Parameters enumType − The enumeration type whose constant's string name you want to retrieve. value − The value of a particular enumerated constant in terms of its underlying type. ...

Read More

C# into keyword

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 176 Views

The into keyword in C# LINQ is used to create intermediate query expressions. It allows you to continue a query after a select or group clause by introducing a new range variable that represents the results of the previous query operation. Syntax Following is the syntax for using the into keyword in LINQ queries − from element in collection select expression into newVariable where condition select finalExpression The into keyword can also be used with group operations − from element in collection group element by key into groupVariable where groupCondition select groupExpression ...

Read More
Showing 31–40 of 730 articles
« Prev 1 2 3 4 5 6 73 Next »
Advertisements