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
C# Program to return specified number of elements from the end of an array
The TakeLast() method in C# returns a specified number of elements from the end of a sequence. It's part of the LINQ library and provides an efficient way to extract the last few elements from arrays, lists, or other enumerable collections. Syntax Following is the syntax for using TakeLast() − IEnumerable TakeLast(int count) Parameters count − The number of elements to return from the end of the sequence. Return Value Returns an IEnumerable containing the specified number of elements from the end of the source sequence. Using TakeLast() ...
Read MoreC# program to find maximum and minimum element in an array
To find the maximum and minimum elements in an array in C#, we initialize both values to the first element of the array and then compare each subsequent element. This approach ensures we correctly identify the extreme values regardless of the array's content. Algorithm The algorithm follows these steps − Initialize both max and min variables to the first array element. Iterate through the array starting from the second element (index 1). Compare each element with the current max and min values. Update max and min accordingly when a larger or smaller element is found. ...
Read MoreC# TimeSpan Min value
The TimeSpan structure in C# represents a time interval or duration. The TimeSpan.MinValue property returns the minimum possible value that a TimeSpan can represent, which is approximately -10.7 million days. This minimum value is useful when you need to initialize a TimeSpan variable to the smallest possible value or when performing comparisons to find the minimum time span in a collection. Syntax Following is the syntax to access the minimum TimeSpan value − TimeSpan.MinValue Return Value The TimeSpan.MinValue property returns a TimeSpan object representing the minimum possible time interval, which equals approximately ...
Read MoreChar.IsLower() Method in C#
The Char.IsLower() method in C# is used to determine whether a specified Unicode character is categorized as a lowercase letter. This method is part of the System.Char class and provides a convenient way to validate character case in string processing operations. Syntax Following is the syntax for the Char.IsLower() method − public static bool IsLower(char ch); Parameters ch − The Unicode character to evaluate. Return Value Returns true if the character is a lowercase letter; otherwise, false. Using Char.IsLower() with Uppercase Characters The following example ...
Read MoreHow to find the index of an item in a C# list in a single step?
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 MoreDeclare char arrays in C#
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 MoreC# TimeSpan Max value
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 MoreGenerics vs non-generics in C#
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 MoreHow to find the Rank of a given Array in C#?
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 MoreCompareTo() method in C#
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