Samual Sam

Samual Sam

1,507 Articles Published

Articles by Samual Sam

Page 28 of 151

Tuple Rest Property in C#

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

The Rest property in C# tuples allows you to create tuples with eight or more elements by nesting additional tuple objects. When a tuple has more than seven elements, the eighth and subsequent elements are stored in the Rest property as a nested tuple. Syntax The general structure for an 8-element tuple using the Rest property is − Tuple Where TRest is another tuple type containing the remaining elements. You can create such tuples using Tuple.Create() − var myTuple = Tuple.Create(item1, item2, item3, item4, item5, item6, item7, item8); How the ...

Read More

How to calculate the power exponent value using C#?

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

To calculate the power exponent value in C#, use the Math.Pow() method from the System namespace. This method raises a number to a specified power and returns the result as a double. Syntax Following is the syntax for the Math.Pow() method − public static double Pow(double x, double y) Parameters x − The base number (of type double). y − The exponent (of type double). Return Value Returns a double value representing x raised to the power of y (xy). Using Math.Pow() with Integers ...

Read More

Inheritance vs Composition in C#

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

In C#, there are two fundamental ways to establish relationships between classes: inheritance and composition. Inheritance creates an "IS-A" relationship where a derived class inherits behavior from a base class, while composition creates a "HAS-A" relationship where one class contains instances of other classes as components. Inheritance Inheritance allows you to designate that a new class should inherit the members of an existing class. The existing class is called the base class, and the new class is referred to as the derived class. Inheritance implements the IS-A relationship. For example, mammal IS-A animal, dog IS-A mammal, hence dog ...

Read More

C# program to find additional values in two lists

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

Finding additional values between two lists is a common requirement in C# programming. This involves identifying elements that exist in one list but not in another. The Except() method from LINQ provides an efficient way to find the difference between two collections. Syntax The Except() method returns elements from the first sequence that are not present in the second sequence − IEnumerable result = list1.Except(list2); To find differences in both directions, you can use − var onlyInList1 = list1.Except(list2); var onlyInList2 = list2.Except(list1); Using Except() to Find Additional Values ...

Read More

How to pop the first element from a C# List?

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

To pop the first element from a C# List, you can use the RemoveAt() method with index 0. This method removes the element at the specified position and shifts all subsequent elements one position to the left. Unlike traditional stack pop operations that return the removed element, RemoveAt() only removes the element. If you need both removal and retrieval, you must first get the element before removing it. Syntax Following is the syntax for removing the first element − list.RemoveAt(0); Following is the syntax for popping (retrieving and removing) the first element − ...

Read More

C# program to find the length of the Longest Consecutive 1's in Binary Representation of a given integer

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

Finding the longest consecutive 1's in the binary representation of a number is a common bit manipulation problem. The key is to use the bitwise AND operation combined with left shift to eliminate consecutive 1's one group at a time. Syntax The core operation uses bitwise AND with left shift − i = (i & (i

Read More

C# Program to get the type of the specified Enumeration

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

Use the GetType() method to get the type of the specified enumeration in C#. This method returns a Type object that represents the actual enumeration type, which is useful for reflection, debugging, and type checking operations. When working with enumeration values, you can retrieve both the enumeration type and its underlying type using built-in methods provided by the Enum class and Type class. Syntax Following is the syntax for getting the type of an enumeration − Type enumType = enumValue.GetType(); To get the underlying type of an enumeration − Type underlyingType ...

Read More

How to validate a URL using regular expression in C#?

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

To validate a URL using regular expressions in C#, you need to check for proper URL structure including protocols, domain names, and top-level domains. Regular expressions provide a powerful way to match URL patterns and ensure they conform to expected formats. URL Components to Validate A valid URL typically consists of the following components − Protocol: http or https Domain: The website name (e.g., example, google) Top-level domain: .com, .org, .net, .edu, etc. Optional path and query parameters: Additional URL components URL Structure Breakdown https:// ...

Read More

How to write multi-line comments in C#?

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

Multi-line comments in C# are comments that span more than one line. They are useful for adding detailed explanations, documenting code blocks, or temporarily disabling large sections of code during development. Syntax Multi-line comments in C# use the following syntax − /* This is a multi-line comment that can span multiple lines All text between /* and */ is ignored */ The compiler ignores everything between /* and */, making it perfect for lengthy explanations or code documentation. Basic Multi-line Comment Example using System; ...

Read More

How to convert Trigonometric Angles in Radians using C#?

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

To convert trigonometric angles from degrees to radians in C#, multiply the degree value by Math.PI/180. Most trigonometric functions in C# expect angles in radians, so this conversion is essential for accurate calculations. Syntax Following is the syntax for converting degrees to radians − double radians = degrees * (Math.PI / 180.0); Following is the syntax for converting radians to degrees − double degrees = radians * (180.0 / Math.PI); Converting Degrees to Radians Example The following example shows how to properly convert degrees to radians before using ...

Read More
Showing 271–280 of 1,507 articles
« Prev 1 26 27 28 29 30 151 Next »
Advertisements