Programming Articles

Page 95 of 2547

How to find the index of an item in a C# list in a single step?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 41K+ Views

To find the index of an item in a C# list in a single step, you can use several built-in methods. The most common approaches are IndexOf() for exact matches and FindIndex() for condition-based searches. Syntax For exact item matching − int index = list.IndexOf(item); For condition-based searching − int index = list.FindIndex(predicate); Using IndexOf() for Exact Matches The IndexOf() method returns the zero-based index of the first occurrence of the specified item − using System; using System.Collections.Generic; public class Program { public ...

Read More

Declare char arrays in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 7K+ Views

A char array in C# is used to store a sequence of characters. You can declare and initialize char arrays in several ways, depending on whether you know the values at compile time or need to set them dynamically. Syntax Following are the different ways to declare a char array − // Declaration with size char[] arr = new char[size]; // Declaration with initialization char[] arr = {'a', 'b', 'c'}; // Alternative initialization syntax char[] arr = new char[] {'a', 'b', 'c'}; Declaring and Setting Elements Individually You can declare a ...

Read More

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

Generics vs non-generics in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 6K+ Views

There are two main types of collections in C#: generic collections and non-generic collections. The primary difference lies in type safety, performance, and how they handle different data types. Generic Collections Generic collections are type-safe and hold elements of the same data type. They provide better performance as they avoid boxing and unboxing operations for value types. Key Features Type Safety: Compile-time type checking prevents runtime errors Better Performance: No boxing/unboxing for value types IntelliSense Support: Better code completion and error detection Common Generic Collections List − Dynamic array of type ...

Read More

How to find the Rank of a given Array in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 344 Views

The rank of an array in C# refers to the number of dimensions it has. A one-dimensional array has a rank of 1, a two-dimensional array has a rank of 2, and so on. To find the rank of any array, use the Rank property. Syntax Following is the syntax to get the rank of an array − arrayName.Rank Return Value The Rank property returns an int value representing the number of dimensions in the array. Using Rank Property with Different Array Types Example 1: Single-Dimensional Array using System; ...

Read More

CompareTo() method in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 1K+ Views

The CompareTo() method in C# is used to compare two values and returns an integer that indicates their relative position in the sort order. This method is part of the IComparable interface and is available for most built-in data types like integers, strings, and dates. Syntax Following is the syntax for using the CompareTo() method − int result = value1.CompareTo(value2); Return Value The CompareTo() method returns the following integer values − 0 = both values are equal Positive integer (typically 1) = the calling value is greater than the parameter Negative ...

Read More

C# Program to get the absolute value of the time

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 1K+ Views

To get the absolute value of time, use the TimeSpan.Duration()

Read More

DateTime.Equals() Method in C#

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

The DateTime.Equals() method in C# is used to check whether two DateTime objects or instances are equal or not. It returns true if both are equal, otherwise false. This method performs a tick-by-tick comparison, meaning it compares the exact moment in time down to the smallest unit (100-nanosecond intervals). Two DateTime objects are considered equal only if they represent the exact same point in time. Syntax Following is the syntax for the static DateTime.Equals() method − public static bool Equals(DateTime date1, DateTime date2); Parameters date1 − The first DateTime object ...

Read More

Decimal.ToInt32() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 151 Views

The Decimal.ToInt32() method in C# is used to convert the value of the specified Decimal to the equivalent 32-bit signed integer. This method performs truncation, meaning it removes the fractional part without rounding. Syntax Following is the syntax − public static int ToInt32(decimal val); Parameters val − The decimal number to convert to a 32-bit signed integer. Return Value Returns an int value that represents the truncated decimal value. If the decimal has fractional digits, they are discarded (not rounded). How It Works The method truncates the decimal value ...

Read More

Why do we use internal keyword in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 3K+ Views

The internal keyword in C# is an access modifier that provides assembly-level access. It allows class members to be accessible within the same assembly but restricts access from other assemblies, making it ideal for creating APIs that should only be used internally within your project. Syntax Following is the syntax for declaring internal members − internal class ClassName { // class accessible within assembly only } class MyClass { internal int field; // field accessible within assembly ...

Read More
Showing 941–950 of 25,467 articles
« Prev 1 93 94 95 96 97 2547 Next »
Advertisements