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
Programming Articles
Page 844 of 2547
Group by Operator in C#
The Group By operator in C# is used to group elements in a collection based on a specified key. It separates the results into groups where each group contains elements that share the same key value. Syntax Following is the syntax for using Group By with LINQ query syntax − var result = from element in collection group element by keySelector; Following is the syntax for using Group By with method syntax − var result = collection.GroupBy(keySelector); ...
Read MoreC# Cast method
The Cast() method in C# is a LINQ extension method used to cast each element in a collection from one type to another. It is particularly useful when working with collections of object type that need to be converted to a specific type for further processing. Syntax Following is the syntax for the Cast() method − public static IEnumerable Cast(this IEnumerable source) Parameters source − The collection containing elements to be cast. TResult − The target type to cast elements to. Return Value Returns an IEnumerable containing each element ...
Read MoreExtracting MAC address using C#
A MAC address (Media Access Control address) is a unique identifier assigned to network interfaces for communications at the data link layer of a network segment. It serves as a network address for most IEEE 802 network technologies, including Ethernet, Wi-Fi, and Bluetooth. In C#, you can extract MAC addresses using the NetworkInterface class from the System.Net.NetworkInformation namespace. This class provides methods to enumerate all network interfaces on the local computer and retrieve their physical addresses. Syntax Following is the syntax for getting all network interfaces − NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); Following is ...
Read MoreConvert.ToBoolean(String, IFormatProvider) Method in C#
The Convert.ToBoolean(String, IFormatProvider) method in C# converts a string representation to an equivalent Boolean value using culture-specific formatting information. This method accepts only specific string values: "True", "False", or their equivalents in different cultures. Syntax Following is the syntax − public static bool ToBoolean(string value, IFormatProvider provider); Parameters value − A string containing the value of either TrueString or FalseString. provider − An object that supplies culture-specific formatting information (this parameter is ignored for Boolean conversions). Return Value Returns true if value equals TrueString, or false if value equals ...
Read MoreWhat are the differences between class methods and class members in C#?
In C#, understanding the difference between class members and class methods is fundamental to object-oriented programming. Class members are the data components that store the state of an object, while class methods are the functions that operate on that data and define the object's behavior. Class Members vs Class Methods Class Members Class Methods Store data and represent the state of an object Define behavior and operations on the object's data Examples: fields, properties, constants Examples: functions, procedures, constructors Hold values that can change over time Execute ...
Read MoreHow to iterate any Map in C#
C# doesn't have a built-in Map type like Java. Instead, C# uses Dictionary to achieve the same functionality. A Dictionary stores key-value pairs and provides several ways to iterate through its contents. Syntax Following is the syntax for creating a Dictionary − Dictionary dictionary = new Dictionary(); Following are the common iteration patterns − // Iterate over keys foreach (var key in dictionary.Keys) { } // Iterate over values foreach (var value in dictionary.Values) { } // Iterate over key-value pairs foreach (var kvp in dictionary) { } ...
Read MoreC# Linq Contains Method
The Contains() method in LINQ is used to check whether a sequence contains a specific element. It returns true if the element is found, otherwise false. This method works with any IEnumerable collection including arrays, lists, and queryable sequences. Syntax Following is the syntax for using Contains() with collections − bool result = collection.Contains(element); Following is the syntax for using Contains() with queryable sequences − bool result = collection.AsQueryable().Contains(element); Parameters element − The value to locate in the sequence. Return Value Returns true if the ...
Read MoreChar.ConvertToUtf32(String, Int32) Method in C#
The Char.ConvertToUtf32(String, Int32) method in C# is used to convert the value of a UTF-16 encoded character or surrogate pair at a specified position in a string into a Unicode code point. This method is particularly useful when working with Unicode characters that may be represented as surrogate pairs in UTF-16 encoding. Syntax Following is the syntax − public static int ConvertToUtf32(string s, int index); Parameters s − The string that contains a character or surrogate pair. index − The index position of the character or surrogate pair in ...
Read MoreC# Program to display name of Current Thread
To display the name of the current thread in C#, use the Name property of the Thread.CurrentThread object. This property allows you to both set and retrieve the name of the currently executing thread. Syntax Following is the syntax to get the current thread − Thread thread = Thread.CurrentThread; Following is the syntax to set and get the thread name − thread.Name = "ThreadName"; string currentName = thread.Name; Using Thread.CurrentThread Property The Thread.CurrentThread property returns a reference to the currently executing thread. You can then use the Name property ...
Read MoreMethods of the Thread Class
The Thread class in C# provides several methods to control and manage thread execution. The most commonly used methods are Start(), Sleep(), Join(), and Abort() (though Abort() is obsolete in .NET Core and later versions). Commonly Used Thread Methods Method Description Start() Starts the execution of a thread Sleep(int milliseconds) Pauses the current thread for specified time Join() Blocks calling thread until this thread terminates Interrupt() Interrupts a thread in WaitSleepJoin state Using Start() and Join() Methods The Start() method ...
Read More