Articles on Trending Technologies

Technical articles with clear explanations and examples

Compare this instance is equal to a specified object or Int64 in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 138 Views

The Equals() method in C# is used to compare whether the current instance of a long (Int64) is equal to a specified object or another Int64 value. This method performs value-based comparison and returns a boolean result. Syntax Following is the syntax for the Equals() method − public bool Equals(long value) public override bool Equals(object obj) Parameters value − A long value to compare with the current instance. obj − An object to compare with the current instance. Return Value Returns true if the current ...

Read More

What is the use of yield return in C#?

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

The yield return keyword in C# enables lazy evaluation and custom iteration over collections. When you use yield return, the method becomes an iterator that returns values one at a time, pausing execution between each return and resuming where it left off when the next value is requested. Syntax Following is the syntax for using yield return − public static IEnumerable MethodName() { // some logic yield return value; // more logic yield return anotherValue; } You can ...

Read More

Get the hash code for the current Int64 instance in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 191 Views

The GetHashCode() method in C# returns a hash code for the current Int64 instance. This method is inherited from the Object class and is commonly used in hash-based collections like Dictionary and HashSet to efficiently store and retrieve values. Hash codes are 32-bit integers that provide a quick way to compare objects for equality. Two equal Int64 values will always have the same hash code, but different values may occasionally produce the same hash code (called a collision). Syntax Following is the syntax for getting the hash code of an Int64 value − public override ...

Read More

What is the difference between Last() and LastOrDefault() in Linq C#?

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

Both Last() and LastOrDefault() are LINQ extension methods that retrieve the last element from a sequence. The key difference is how they handle empty sequences or no matching elements: Last() throws an InvalidOperationException when no element is found, while LastOrDefault() returns the default value for the type (null for reference types, 0 for integers, etc.). Syntax Following is the syntax for Last() method − public static T Last(this IEnumerable source); public static T Last(this IEnumerable source, Func predicate); Following is the syntax for LastOrDefault() method − public static T LastOrDefault(this IEnumerable source); ...

Read More

C# Program to Check if an Array is Sorted

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 5K+ Views

We are given an array, and we need to check whether the array is sorted or not. The array can be sorted in either ascending or descending order. In this article, we will discuss different approaches to check if an array is sorted using C#. Problem Examples Input: array = {1, 2, 3, 4, 5} Output: True Explanation: The array is sorted in ascending order. Input: array = {29, 28, 27, 26, 25, 24} Output: True Explanation: The array is sorted in descending order. Input: array = {12, 10, 19, 11, 9} Output: False Explanation: The ...

Read More

Check whether the specified Unicode character is a punctuation mark in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 332 Views

The Char.IsPunctuation() method in C# determines whether a specified Unicode character is classified as a punctuation mark. This method returns true if the character belongs to any punctuation category, otherwise it returns false. Punctuation marks include characters like periods, commas, semicolons, exclamation points, question marks, brackets, and other symbols used for punctuation in text. Syntax Following is the syntax for the Char.IsPunctuation() method − public static bool IsPunctuation(char c) Parameters c − The Unicode character to evaluate. Return Value Returns true if the character is a ...

Read More

How to remove element from the specified index of the List in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 313 Views

To remove an element from a specified index in a List in C#, you use the RemoveAt() method. This method removes the element at the given index and automatically shifts all subsequent elements one position to the left. Syntax Following is the syntax for the RemoveAt() method − list.RemoveAt(int index); Parameters index − The zero-based index of the element to remove. Must be a valid index (0 ≤ index < Count). Using RemoveAt() with String List The following example demonstrates removing an element at index 5 from a list ...

Read More

How to get Synchronize access to an Array in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 212 Views

To get synchronized access to an array in C#, you can use the SyncRoot property of the array along with the lock statement. This ensures thread-safe access when multiple threads are accessing the same array concurrently. The SyncRoot property returns an object that can be used to synchronize access to the array, preventing data races and ensuring thread safety in multi-threaded applications. Syntax Following is the syntax for synchronizing access to an array − lock(array.SyncRoot) { // Thread-safe operations on the array foreach (var item in array) { ...

Read More

How to get Seventh Element of the Tuple in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 158 Views

A Tuple in C# is a data structure that can hold multiple values of different types. To access the seventh element of a tuple, you use the Item7 property. This property is available in tuples that have seven or more elements. Syntax Following is the syntax for accessing the seventh element of a tuple − var seventhElement = tupleName.Item7; For creating a tuple with seven elements − var tuple = Tuple.Create(item1, item2, item3, item4, item5, item6, item7); Using Item7 Property The Item7 property directly retrieves the seventh element from ...

Read More

How to retrieve the system's reference to the specified String in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 130 Views

The string.Intern() method in C# retrieves the system's reference to the specified string from the intern pool. The intern pool is a table maintained by the .NET runtime that contains references to all string literals and interned strings to optimize memory usage by ensuring that identical strings share the same memory location. Syntax Following is the syntax for the string.Intern() method − public static string Intern(string str) Parameters str − The string to search for in the intern pool. Return Value Returns a reference to the string ...

Read More
Showing 9741–9750 of 61,297 articles
« Prev 1 973 974 975 976 977 6130 Next »
Advertisements