Programming Articles

Page 36 of 2547

Searching the index of specified object in Collection in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 184 Views

In C#, you can search for the index of a specified object in a collection using the IndexOf() method. This method returns the zero-based index of the first occurrence of the specified object, or -1 if the object is not found. Syntax The basic syntax for finding the index of an object in a collection − int index = collection.IndexOf(objectToFind); Return Value Returns the zero-based index of the first occurrence of the specified object. Returns -1 if the object is not found in the collection. Using ...

Read More

What if we are not sure of the type of value that we want to store in a variable. How to handle this in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 120 Views

As C# is a strongly-typed language, every variable and constant has a pre-defined type. Before using any variable, we must tell the compiler what type of value a variable will store. If we are not sure about the type, then it is handled using dynamic programming. Dynamic programming is supported by the dynamic keyword, which allows variables to bypass compile-time type checking and have their types resolved at runtime. Syntax Following is the syntax for declaring a dynamic variable − dynamic variableName = value; The type of the variable is determined at runtime ...

Read More

C# Program to Sort a List of Employees Based on Salary using LINQ

Sabid Ansari
Sabid Ansari
Updated on 17-Mar-2026 1K+ Views

In many software development projects, there comes a point where it becomes necessary to sort a list of objects based on one or more properties of the objects. In C#, the LINQ (Language Integrated Query) library provides a powerful and easy-to-use way to sort lists of objects based on one or more criteria. In this tutorial, we will demonstrate how to sort a list of Employee objects based on their salary using LINQ. Syntax Following is the syntax for sorting a list using LINQ OrderBy methods − // Sort in ascending order var sortedList = list.OrderBy(item ...

Read More

Console.ReadLine() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 1K+ Views

The Console.ReadLine() method in C# is used to read the next line of characters from the standard input stream. It reads input from the user until the Enter key is pressed and returns the input as a string. This method is commonly used in console applications to capture user input for processing. It waits for user input and returns null if the input stream has been redirected and no more lines are available. Syntax Following is the syntax for the Console.ReadLine() method − public static string ReadLine(); Return Value The method returns ...

Read More

Stack.CopyTo() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 143 Views

The Stack.CopyTo() method in C# is used to copy all elements of a Stack to an existing one-dimensional Array, starting at a specified array index. This method is useful when you need to transfer stack data into an array for further processing or storage. Syntax Following is the syntax of the Stack.CopyTo() method − public virtual void CopyTo(Array arr, int index); Parameters arr − The one-dimensional Array that is the destination of the elements copied from Stack. The Array must have zero-based indexing. index − The zero-based index in ...

Read More

Gets or sets the value of the bit at a specific position in the BitArray in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 171 Views

The BitArray class in C# provides an indexer that allows you to get or set the value of a bit at a specific position. You can access individual bits using either the indexer syntax arr[index] or the Get() and Set() methods. Syntax Following is the syntax for accessing bits in a BitArray − // Using indexer to get/set bits bitArray[index] = true; // Set bit at index bool value = bitArray[index]; // Get bit at index // Using Get() and Set() methods bool value = bitArray.Get(index); // Get bit at index bitArray.Set(index, ...

Read More

Search for an element matching the conditions and return the zero-based index of the last occurrence within the entire List in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 247 Views

The FindLastIndex() method in C# searches for an element that matches the conditions defined by a specified predicate and returns the zero-based index of the last occurrence within the entire List. This method is particularly useful when you need to find the rightmost element that satisfies certain criteria. Syntax Following is the syntax for the FindLastIndex() method − public int FindLastIndex(Predicate match) Parameters match − The Predicate delegate that defines the conditions of the element to search for. Return Value Returns the zero-based index of the last ...

Read More

How to Create a HashTable Collection in C#?

Shilpa Nadkarni
Shilpa Nadkarni
Updated on 17-Mar-2026 292 Views

The Hashtable is a non-generic collection in C# that stores key-value pairs, similar to a generic Dictionary collection. Hashtable is defined in the System.Collections namespace and computes hash codes for keys to optimize lookups by storing them in different internal buckets. In this tutorial, we will see how to create a Hashtable collection in C# using different approaches. Key Features of Hashtable Stores key-value pairs as DictionaryEntry objects Keys must be unique and non-null, but values can be null or duplicate Keys are immutable objects that provide hash functions Values can be accessed using keys in ...

Read More

What is the use of "is" keyword in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 428 Views

The is keyword in C# is used to check if an object is of a specific type or can be cast to that type. It returns a Boolean value — true if the object is compatible with the specified type, false otherwise. The is keyword is particularly useful for type checking before performing type conversions, ensuring safe downcasting in inheritance hierarchies, and working with polymorphic objects. Syntax Following is the syntax for using the is keyword − object is Type The is keyword can also be used with pattern matching (C# 7.0+) − ...

Read More

How to convert an integer to string with padding zero in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 2K+ Views

Converting an integer to a string with padding zeros is a common requirement in C# programming. This allows you to format numbers with a consistent width by adding leading zeros. There are several approaches to achieve this, each with its own syntax and use cases. Syntax Following are the common syntaxes for zero-padding integers − // Using PadLeft method number.ToString().PadLeft(width, '0'); // Using custom numeric format number.ToString("0000"); // Using standard numeric format number.ToString("D4"); // Using string interpolation $"{number:0000}" Using PadLeft Method The PadLeft method pads the beginning of a string ...

Read More
Showing 351–360 of 25,467 articles
« Prev 1 34 35 36 37 38 2547 Next »
Advertisements