Programming Articles

Page 89 of 2547

C# program to remove an item from Set

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 308 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 80 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

Final local variables in C#

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

In C#, there is no direct equivalent to Java's final keyword for local variables. However, you can achieve similar behavior using the readonly keyword for fields and implicit typing with var or const for local variables that should not change after initialization. The readonly keyword allows a field to be assigned a value only once − either at the time of declaration or in the constructor. Once assigned, it cannot be modified. Syntax Following is the syntax for declaring a readonly field − readonly dataType fieldName; For local variables that should remain constant, ...

Read More

C# Program to replace a special character from a String

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

The Replace() method in C# is used to replace all occurrences of a specified character or substring in a string with a new character or substring. This method is particularly useful for removing or replacing special characters from strings. Syntax Following is the syntax for replacing characters using the Replace() method − string.Replace(oldChar, newChar) string.Replace(oldString, newString) Parameters oldChar/oldString − The character or string to be replaced. newChar/newString − The character or string to replace with. Return Value The Replace()

Read More
Showing 881–890 of 25,467 articles
« Prev 1 87 88 89 90 91 2547 Next »
Advertisements