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 57 of 2547
What is Shallow Copy and how it is different from Deep Copy in C#?
A shallow copy creates a new object but copies only the reference values from the original object. When the copied object contains reference types, both the original and copied objects point to the same memory locations for those inner objects. A deep copy creates a completely independent copy of an object, including all nested objects. Changes to one object do not affect the other since they occupy separate memory spaces. Shallow Copy vs Deep Copy Shallow Copy ...
Read MoreTimeSpan.FromSeconds() Method in C#
The TimeSpan.FromSeconds() method in C# is used to return a TimeSpan that represents a specified number of seconds, where the specification is accurate to the nearest millisecond. This static method is particularly useful when you need to create time intervals based on second values. Syntax Following is the syntax for the TimeSpan.FromSeconds() method − public static TimeSpan FromSeconds(double value); Parameters value − A number of seconds, accurate to the nearest millisecond. Can be positive, negative, or zero. Return Value Returns a TimeSpan object that represents the specified number of ...
Read MoreGet an ICollection containing keys in OrderedDictionary in C#
The OrderedDictionary class in C# maintains the insertion order of elements. To get an ICollection containing keys from an OrderedDictionary, you can use the Keys property which returns an ICollection object containing all the keys in their insertion order. Syntax Following is the syntax to get keys as an ICollection from OrderedDictionary − OrderedDictionary dict = new OrderedDictionary(); ICollection keys = dict.Keys; Using Keys Property with CopyTo Method The most common approach is to use the Keys property and copy the keys to a string array using the CopyTo method − ...
Read MoreHow to make use of both Take and Skip operator together in LINQ C#?
The Take and Skip operators in LINQ C# are powerful tools for data manipulation. The Skip operator skips over a specified number of elements from the beginning of a sequence, while the Take operator returns a specified number of elements from the beginning of a sequence. When used together, Skip and Take enable you to implement pagination and extract specific ranges of data from collections. This combination is particularly useful for scenarios like displaying search results in pages or processing data in chunks. Syntax Following is the syntax for using Skip operator − var result ...
Read MoreC# BitConverter.ToUInt16() Method
The BitConverter.ToUInt16() method in C# converts two consecutive bytes from a byte array into a 16-bit unsigned integer (ushort). This method is particularly useful when working with binary data, network protocols, or file formats that store numeric values as byte sequences. Syntax public static ushort ToUInt16(byte[] value, int startIndex); Parameters value: The byte array containing the bytes to convert. startIndex: The starting position within the byte array (must have at least 2 bytes remaining). Return Value Returns a 16-bit unsigned integer (ushort) formed by combining two bytes from the specified ...
Read MoreCheck if HashSet and the specified collection contain the same elements in C#
To check if a HashSet and another collection contain the same elements in C#, use the SetEquals() method. This method returns true if both collections have identical elements, regardless of order, and false otherwise. Syntax Following is the syntax for the SetEquals() method − public bool SetEquals(IEnumerable other) Parameters other − The collection to compare with the current HashSet. Return Value Returns true if the HashSet and the specified collection contain the same elements; otherwise, false. Using SetEquals() with Different Elements When the HashSet and another collection ...
Read MoreHow to create an array with non-default repeated values in C#?
We can create an array with non-default repeated values using Enumerable.Repeat(). This method creates a sequence that contains one repeated value a specified number of times. It requires the System.Linq namespace to be included. Syntax Following is the syntax for using Enumerable.Repeat() − IEnumerable Enumerable.Repeat(T element, int count) Parameters element − The value to be repeated in the sequence. count − The number of times to repeat the value in the generated sequence. Return Value Returns an IEnumerable that contains a repeated value. To convert ...
Read MoreFetch the maximum value from a MySQL column?
To fetch the maximum value from a MySQL column in C#, you need to establish a database connection and execute a query using either the MAX() function or ORDER BY with LIMIT. This tutorial demonstrates both approaches using MySQL.Data.MySqlClient. Syntax Following is the syntax for fetching maximum value using the MAX() function − SELECT MAX(column_name) FROM table_name; Following is the syntax using ORDER BY with LIMIT − SELECT column_name FROM table_name ORDER BY column_name DESC LIMIT 1; Database Setup First, let us create a table and insert sample data ...
Read MoreHow to force garbage collection in C#?
The garbage collector in C# automatically manages memory by removing unused objects. However, you can force garbage collection to run immediately using the GC.Collect() method, though this is generally not recommended due to performance implications. Forcing garbage collection should only be used in specific scenarios where you know large amounts of memory have been freed and want to clean up immediately, such as after closing a large document or completing a memory-intensive operation. Syntax Following is the syntax for forcing garbage collection − GC.Collect(); To collect specific generations − GC.Collect(int generation); ...
Read MoreTimeSpan.FromTicks() Method in C#
The TimeSpan.FromTicks() method in C# is used to create a TimeSpan object that represents a specified time duration in ticks. A tick represents one hundred nanoseconds or one ten-millionth of a second, making it the smallest unit of time measurement in .NET. Syntax Following is the syntax for the TimeSpan.FromTicks() method − public static TimeSpan FromTicks(long val); Parameters The method accepts the following parameter − val − A long integer representing the number of ticks. Each tick equals 100 nanoseconds. Return Value Returns a TimeSpan object that represents ...
Read More