Programming Articles

Page 871 of 2547

DateTimeOffset.AddYears() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 109 Views

The DateTimeOffset.AddYears() method in C# is used to add a specified number of years to a DateTimeOffset instance. This method returns a new DateTimeOffset object representing the date and time with the added years, while preserving the original offset from UTC. Syntax Following is the syntax for the DateTimeOffset.AddYears() method − public DateTimeOffset AddYears(int years); Parameters The method takes one parameter − years − An integer representing the number of years to add. Use positive values to add years, negative values to subtract years. Return Value ...

Read More

How to declare a tuple in C#?

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

A tuple in C# is a data structure that can hold multiple values of different types. Tuples are useful when you need to return multiple values from a method or group related data together without creating a separate class. C# provides two main ways to declare tuples: the classic Tuple class and the newer value tuples introduced in C# 7.0 with cleaner syntax. Syntax Classic tuple syntax − Tuple tuple = new Tuple(value1, value2); Value tuple syntax (C# 7.0+) − (int, string) tuple = (value1, value2); // or with named elements ...

Read More

How to check if two Strings are anagrams of each other using C#?

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

An anagram is a word or phrase formed by rearranging the letters of another word or phrase, using all the original letters exactly once. For example, "silent" and "listen" are anagrams because they contain the same letters in different arrangements. In C#, there are several approaches to check if two strings are anagrams. The most common method is to sort the characters of both strings and compare them for equality. Using Array.Sort() Method The simplest approach is to convert both strings to character arrays, sort them, and then compare the sorted arrays − ...

Read More

Convert.ToUInt16 Method in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 307 Views

The Convert.ToUInt16 method in C# converts a specified value to a 16-bit unsigned integer (ushort). This method can convert various data types including strings, integers, doubles, and other numeric types to a ushort value ranging from 0 to 65, 535. Syntax Following are the common overloads of the Convert.ToUInt16 method − public static ushort ToUInt16(string value); public static ushort ToUInt16(int value); public static ushort ToUInt16(double value); public static ushort ToUInt16(bool value); Parameters value − The value to convert to a 16-bit unsigned integer. Can be a string representation of a number, numeric ...

Read More

Enum with Customized Value in C#

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

An enum (enumeration) in C# is used to store a set of named constants such as days of the week, months, seasons, or any fixed collection of related values. By default, enum constants start from 0 and increment by 1, but you can customize these values to match your specific requirements. Customizing enum values is useful when you need specific numeric representations, want to maintain compatibility with external systems, or need non-sequential numbering. Syntax Following is the syntax for declaring an enum with customized values − public enum EnumName { Value1 ...

Read More

DateTimeOffset.Compare() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 3K+ Views

The DateTimeOffset.Compare() method in C# is used to compare two DateTimeOffset objects and indicates whether the first is earlier than the second, equal to the second, or later than the second. It returns an integer value that represents the relationship between the two dates. 0 − If val1 is later than val2 DateTimeOffset.Compare() Return Values < 0 val1 is earlier than val2 0 val1 equals val2 > 0 ...

Read More

Enumerable.Repeat method in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 3K+ Views

The Enumerable.Repeat method is part of the System.Linq namespace and creates a sequence that contains the same element repeated a specified number of times. This method is useful for initializing collections or generating test data with repeated values. Syntax Following is the syntax for the Enumerable.Repeat method − public static IEnumerable Repeat(TResult element, int count) Parameters element − The value to be repeated in the resulting sequence. count − The number of times to repeat the element. Return Value Returns an IEnumerable that contains the ...

Read More

Comparing dates using C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 384 Views

Comparing dates in C# is accomplished using the DateTime structure, which provides built-in comparison operators and methods. The DateTime class allows you to compare dates using standard operators like , ==, and specialized methods like Compare(). Syntax Following is the syntax for creating DateTime objects for comparison − DateTime date1 = new DateTime(year, month, day); DateTime date2 = new DateTime(year, month, day); Following are the comparison operators and methods available − // Using comparison operators if (date1 < date2) { } if (date1 > date2) { } if (date1 == date2) { ...

Read More

How to create 3-Tuple or Triple Tuple in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 500 Views

The Tuple class represents a 3-tuple, also called a triple. A tuple is a data structure that contains a sequence of elements of different types, providing a convenient way to group related data together without creating a custom class. 3-tuples are commonly used for − Easier access to a data set with three related values. Easier manipulation of grouped data. To represent a single set of three related values. To return multiple values from a method. To pass multiple values to a method as a single parameter. ...

Read More

How to find and display the Multiplication Table in C#?

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

A multiplication table displays the product of a number with a sequence of other numbers. In C#, you can generate and display multiplication tables using loops and formatted output. This is useful for educational applications, mathematical calculations, or creating reference tables. Syntax The basic structure for creating a multiplication table uses a loop with formatted output − while (counter

Read More
Showing 8701–8710 of 25,466 articles
« Prev 1 869 870 871 872 873 2547 Next »
Advertisements