Ankith Reddy

Ankith Reddy

730 Articles Published

Articles by Ankith Reddy

Page 7 of 73

C# Linq FirstorDefault Method

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

The FirstOrDefault() method in C# LINQ returns the first element of a sequence, or a default value if the sequence is empty or no element matches the specified condition. This method is useful when you need to safely retrieve the first element without throwing an exception. Syntax Following is the syntax for using FirstOrDefault() − // Without condition public static T FirstOrDefault(this IEnumerable source); // With condition public static T FirstOrDefault(this IEnumerable source, Func predicate); Parameters source − The sequence to return the first element from. predicate (optional) ...

Read More

C# Queryable Min Method

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

The Min() method in C# is used to find the minimum value from a sequence. When used with AsQueryable(), it creates a queryable data source that can be efficiently processed using LINQ expressions. Syntax Following is the syntax for the Queryable Min() method − public static TSource Min(this IQueryable source); public static TResult Min(this IQueryable source, Expression selector); Parameters source: The IQueryable sequence to find the minimum value in. selector: A function to extract a value from each element (optional). Return Value Returns the minimum value in the sequence. ...

Read More

How to use the GetValue() method of array class in C#?

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

The GetValue() method of the Array class in C# retrieves the value at a specified position in a multi-dimensional or single-dimensional array. This method is particularly useful when working with arrays created using Array.CreateInstance(), as it provides a generic way to access array elements regardless of the array's underlying type. Syntax Following is the syntax for using GetValue() with different array dimensions − // For single-dimensional array object value = array.GetValue(index); // For multi-dimensional array object value = array.GetValue(index1, index2); object value = array.GetValue(index1, index2, index3); Parameters index − A 32-bit ...

Read More

What are finalizers in C#?

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

Finalizers in C# are special methods that perform cleanup when an object is being destroyed by the garbage collector. They provide a way to release unmanaged resources before the object is removed from memory. Syntax Following is the syntax for declaring a finalizer − ~ClassName() { // cleanup code here } The finalizer declaration uses a tilde (~) followed by the class name with no parameters or access modifiers. Key Rules Only one finalizer is allowed per class. Finalizers cannot be inherited or overloaded. ...

Read More

C# Program to get the name of the drive

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

The DriveInfo class in C# provides information about drives on the system. You can use the Name property to get the name of a specific drive by passing the drive letter to the DriveInfo constructor. Syntax Following is the syntax for creating a DriveInfo object and getting the drive name − DriveInfo info = new DriveInfo("driveLetter"); string driveName = info.Name; Parameters driveLetter − A string representing the drive letter (e.g., "C", "D", "E"). Return Value The Name property returns a string containing the name of the drive, ...

Read More

TakeWhile method in C# ()

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

The TakeWhile() method in C# is a LINQ extension method that returns elements from the beginning of a sequence as long as a specified condition is true. It stops immediately when the first element that doesn't satisfy the condition is encountered, even if later elements might satisfy the condition. Syntax Following is the syntax for the TakeWhile() method − public static IEnumerable TakeWhile( this IEnumerable source, Func predicate ) Parameters source − The sequence to return elements from. predicate − ...

Read More

C# Program to return the only element that satisfies a condition

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

The Single() method in C# returns the only element from a sequence that satisfies a specified condition. If no element or more than one element satisfies the condition, it throws an InvalidOperationException. This method is part of LINQ and is commonly used when you expect exactly one element to match your criteria. Syntax Following is the syntax for the Single() method − // Without condition - returns the only element public static T Single(this IEnumerable source) // With condition - returns the only element that matches the predicate public static T Single(this IEnumerable source, ...

Read More

Write a C# program to find GCD and LCM?

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

In C#, finding the GCD (Greatest Common Divisor) and LCM (Least Common Multiple) of two numbers is a common mathematical programming task. The GCD is the largest positive integer that divides both numbers without remainder, while the LCM is the smallest positive integer that both numbers can divide evenly. These calculations are frequently used in mathematical applications, fraction simplification, and solving problems involving ratios and proportions. Mathematical Relationship There's an important mathematical relationship between GCD and LCM − GCD(a, b) × LCM(a, b) = a × b This means once we find the ...

Read More

C# Program to return the difference between two sequences

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

In C#, you can find the difference between two sequences using the Except() method from LINQ. This method returns elements from the first sequence that do not appear in the second sequence, effectively performing a set difference operation. Syntax Following is the syntax for using the Except() method − IEnumerable result = firstSequence.Except(secondSequence); Parameters firstSequence − The sequence to return elements from. secondSequence − The sequence whose elements to exclude from the returned sequence. Return Value The method returns an IEnumerable containing the elements from the first sequence that ...

Read More

Properties of the Thread Class

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

A thread is defined as the execution path of a program. Each thread defines a unique flow of control. The Thread class in C# provides various properties to manage and retrieve information about threads during execution. These properties allow you to control thread behavior, get thread status information, and manage cultural settings. Understanding these properties is essential for effective multithreading in C# applications. Thread Class Properties The following table describes the key properties of the Thread class − Property Description Type CurrentContext Gets the current context in which the ...

Read More
Showing 61–70 of 730 articles
« Prev 1 5 6 7 8 9 73 Next »
Advertisements