Articles on Trending Technologies

Technical articles with clear explanations and examples

Byte.CompareTo(Object) Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 156 Views

The Byte.CompareTo(Object) method in C# compares the current byte instance to a specified object and returns an integer that indicates their relative values. This method is useful for sorting operations and determining the ordering relationship between byte values. Syntax Following is the syntax − public int CompareTo(object val); Parameters val − An object to compare, or null. Return Value The method returns an integer with the following meaning − Less than zero − The current instance is less than the value. Zero − The current instance ...

Read More

C# program to convert decimal to Octal number

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

A decimal number can be converted to an octal number using the division method. Octal is a base-8 number system that uses digits 0-7. To convert from decimal to octal, we repeatedly divide the decimal number by 8 and collect the remainders. How It Works The conversion process involves dividing the decimal number by 8 repeatedly and storing the remainders. The octal equivalent is formed by reading the remainders in reverse order − Decimal 40 to Octal Conversion 40 ÷ 8 = 5 ...

Read More

What is the difference between dynamic type variables and object type variables?

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

In C#, both dynamic and object type variables can store values of any type, but they differ significantly in how type checking is performed. Understanding this difference is crucial for writing efficient and safe C# code. The object type is the ultimate base class for all data types in C# Common Type System (CTS). It serves as an alias for System.Object class. All types in C# inherit from object, making it possible to assign any value to an object variable. The dynamic type bypasses compile-time type checking entirely. Operations on dynamic variables are resolved at runtime using the ...

Read More

Tuple.Create method in C#

George John
George John
Updated on 17-Mar-2026 160 Views

The Tuple.Create method in C# is a convenient way to create tuple objects without explicitly specifying their types. The method automatically infers the types from the provided arguments, making tuple creation more concise and readable. Syntax Following is the syntax for using Tuple.Create method − var tupleName = Tuple.Create(item1, item2, ...); The method can accept up to 8 parameters of different types − Tuple.Create(T1 item1); Tuple.Create(T1 item1, T2 item2); // ... up to 8 items Creating Basic Tuples Example Here we create a tuple with a string and ...

Read More

How do we use a #line directive in C#?

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

The #line directive in C# allows you to modify the compiler's line number and optionally the file name that appear in error and warning messages. This is particularly useful for code generators and preprocessors that need to map generated code back to the original source files. Syntax Following is the syntax for the #line directive − #line number #line number "filename" #line default #line hidden Parameters number − The line number you want to assign to the following line filename − Optional filename that will appear in compiler output ...

Read More

Byte.Equals(Byte) Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 368 Views

The Byte.Equals(Byte) method in C# returns a value indicating whether this instance and a specified Byte object represent the same value. This method provides a reliable way to compare two byte values for equality. Syntax Following is the syntax − public bool Equals(byte obj); Parameters obj − A byte object to compare to this instance. Return Value Returns true if obj has the same value as this instance; otherwise, false. Using Byte.Equals() for Value Comparison Example using System; public class Demo { public static ...

Read More

What are contextual keywords in C#?

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

In C#, contextual keywords are special identifiers that have reserved meaning only in specific contexts. Unlike regular keywords, they can still be used as variable names or identifiers when not in their special context. Common examples include get and set in properties, where in LINQ queries, and partial in class definitions. Contextual keywords provide flexibility by allowing the same word to serve as both a keyword and an identifier depending on the context in which it appears. Syntax Contextual keywords are used within their specific contexts. Here are some common patterns − // Property accessors ...

Read More

What are the hidden features of C#?

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

C# contains several powerful but often overlooked features that can significantly improve code readability, safety, and efficiency. These hidden gems can make your C# programming more elegant and productive when used appropriately. Lambda Expressions A lambda expression is a concise way to write anonymous functions using the => operator (called the "goes to" operator). Lambda expressions are commonly used with LINQ operations and delegate assignments. Syntax (parameters) => expression (parameters) => { statements; } Example using System; using System.Linq; class Program { public static void Main() ...

Read More

Difference between prefix and postfix operators in C#?

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

The prefix and postfix operators in C# are increment (++) and decrement (--) operators that behave differently based on their position relative to the variable. The key difference lies in when the increment or decrement occurs and what value is returned. Syntax Following is the syntax for prefix operators − ++variable; // prefix increment --variable; // prefix decrement Following is the syntax for postfix operators − variable++; // postfix increment variable--; // postfix decrement Prefix Operators The prefix operator increments or decrements the variable first, ...

Read More

How to initialize a dictionary to an empty dictionary in C#?

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

To initialize a dictionary to an empty state in C#, there are several approaches. You can create a new empty dictionary directly, use the Clear() method to empty an existing dictionary, or check if a dictionary is already empty using the Count property. Syntax Following is the syntax for creating an empty dictionary − Dictionary dict = new Dictionary(); Following is the syntax for clearing an existing dictionary − dict.Clear(); Following is the syntax for checking if a dictionary is empty − if (dict.Count == 0) { ...

Read More
Showing 11071–11080 of 61,297 articles
Advertisements