Programming Articles

Page 109 of 2547

Time Functions in C#

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

The DateTime structure in C# provides numerous methods and properties for working with dates and times. These time functions allow you to manipulate DateTime instances by adding or subtracting specific time intervals, extracting time components, and performing various time-related operations. Time functions in C# are essential for applications that need to handle scheduling, logging, time calculations, and date arithmetic operations. Common Time Functions The following table shows the most commonly used time manipulation methods in the DateTime class − Method Description AddDays(Double) Returns a new DateTime that adds the ...

Read More

What is index-based I/O BitArray collection in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 234 Views

The BitArray class in C# manages a compact array of bit values represented as Boolean values, where true indicates the bit is on (1) and false indicates the bit is off (0). It is part of the System.Collections namespace and provides an efficient way to store and manipulate bits. BitArray is particularly useful for scenarios requiring bitwise operations, boolean flags, or when memory efficiency is crucial since it stores bits compactly rather than using full bytes for each boolean value. Syntax Following is the syntax for creating a BitArray − BitArray bitArray = new BitArray(size); ...

Read More

C# program to remove an item from Set

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 310 Views

A HashSet in C# is a collection that stores unique elements and provides efficient methods to add, remove, and search items. To remove items from a HashSet, you can use methods like Remove(), RemoveWhere(), or Clear(). Syntax Following are the common methods to remove items from a HashSet − // Remove a specific item bool removed = hashSet.Remove(item); // Remove items based on a condition int count = hashSet.RemoveWhere(predicate); // Remove all items hashSet.Clear(); Using Remove() Method The Remove() method removes a specific item from the HashSet and returns true if ...

Read More

C# Program to get the difference between two dates in seconds

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

In C#, you can calculate the difference between two dates in seconds using the TimeSpan structure. When you subtract one DateTime from another, it returns a TimeSpan object that represents the time interval between them. Syntax Following is the syntax for calculating date difference in seconds − DateTime date1 = new DateTime(year, month, day, hour, minute, second); DateTime date2 = new DateTime(year, month, day, hour, minute, second); TimeSpan difference = date2 - date1; double seconds = difference.TotalSeconds; Using DateTime Subtraction The most straightforward approach is to subtract one DateTime from another, which returns ...

Read More

Decimal.ToUInt64() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 81 Views

The Decimal.ToUInt64() method in C# converts a decimal value to a 64-bit unsigned integer (ulong). This method performs truncation, meaning it removes the fractional part and returns only the integer portion of the decimal number. Syntax Following is the syntax − public static ulong ToUInt64(decimal value); Parameters value − The decimal number to convert to a 64-bit unsigned integer. Return Value Returns a ulong (64-bit unsigned integer) that represents the truncated value of the specified decimal. Decimal to UInt64 Conversion ...

Read More

How to display Absolute value of a number in C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 3K+ Views

To find the absolute value of a number in C#, use the Math.Abs method. The absolute value represents the distance of a number from zero on the number line, always returning a non-negative result. Syntax The Math.Abs method is overloaded to work with different numeric types − Math.Abs(int value) Math.Abs(long value) Math.Abs(float value) Math.Abs(double value) Math.Abs(decimal value) Parameters value − The number whose absolute value is to be computed. Return Value Returns the absolute value of the specified number. If the number is positive or zero, it ...

Read More

C# program to remove all duplicates words from a given sentence

George John
George John
Updated on 17-Mar-2026 1K+ Views

Removing duplicate words from a sentence is a common string manipulation task in C#. This process involves splitting the sentence into individual words, identifying duplicates, and keeping only unique words while preserving the original structure. There are several approaches to accomplish this task, ranging from using LINQ's Distinct() method to using collections like HashSet for efficient duplicate removal. Using LINQ Distinct() Method The Distinct() method from LINQ provides a straightforward way to remove duplicates from a collection − using System; using System.Linq; public class Program { public static void Main() { ...

Read More

Scope of Variables in C#

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

The scope of a variable in C# determines the region of code where a variable can be accessed and used. Understanding variable scope is crucial for writing efficient and error-free programs. C# has several levels of variable scope, each with different accessibility rules and lifetimes. Types of Variable Scope Method Level (Local Variables) Variables declared inside a method are local variables. They are only accessible within that specific method and are destroyed when the method execution completes − using System; class Program { public void TestMethod() { ...

Read More

Calculate minutes between two dates in C#

George John
George John
Updated on 17-Mar-2026 21K+ Views

Calculating the difference in minutes between two dates is a common requirement in C# applications. The DateTime structure and TimeSpan class provide built-in functionality to perform this calculation efficiently. Syntax Following is the basic syntax for calculating minutes between two dates − DateTime date1 = new DateTime(year, month, day, hour, minute, second); DateTime date2 = new DateTime(year, month, day, hour, minute, second); TimeSpan difference = date2 - date1; double minutes = difference.TotalMinutes; How It Works When you subtract one DateTime from another, C# returns a TimeSpan object that represents the time difference. The ...

Read More

Char.GetUnicodeCategory(String, Int32) Method with Examples in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 271 Views

The Char.GetUnicodeCategory(String, Int32) method in C# categorizes the character at the specified position in a specified string into a group identified by one of the UnicodeCategory values. This method is useful for determining the type of character (letter, digit, punctuation, etc.) at a specific index within a string. Syntax Following is the syntax − public static System.Globalization.UnicodeCategory GetUnicodeCategory(string str, int index); Parameters str − The string to examine. index − The zero-based position of the character to categorize within the string. Return Value Returns a UnicodeCategory enumeration value that ...

Read More
Showing 1081–1090 of 25,467 articles
« Prev 1 107 108 109 110 111 2547 Next »
Advertisements