Programming Articles

Page 840 of 2547

Main thread vs child thread in C#

varma
varma
Updated on 17-Mar-2026 980 Views

In C#, every application starts with a main thread that executes the Main method. Additional threads, called child threads, can be created to perform concurrent operations alongside the main thread. Main Thread The main thread is automatically created when a C# program starts execution. It is the first thread to run in a process and is responsible for executing the Main method. The main thread can create and manage other threads during program execution. Child Thread A child thread is any thread created from the main thread using the Thread class or other threading mechanisms. Child ...

Read More

C# Program to write a number in hexadecimal format

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 640 Views

Converting numbers to hexadecimal format in C# can be accomplished using various format specifiers. Hexadecimal is a base-16 number system commonly used in programming for representing binary data in a more readable format. Syntax Following are the main hexadecimal format specifiers in C# − {0:x} // lowercase hexadecimal {0:X} // uppercase hexadecimal {0:x8} // lowercase with 8 digits (zero-padded) {0:X8} // uppercase with 8 digits (zero-padded) You can also use the ToString() method with format specifiers − number.ToString("x") // ...

Read More

C# Program to convert a Double value to an Int64 value

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

To convert a Double value to an Int64 value, use the Convert.ToInt64() method. This method performs a rounded conversion from a 64-bit floating-point number to a 64-bit signed integer. Int64 represents a 64-bit signed integer and is equivalent to the long data type in C#. The conversion truncates the decimal portion and rounds to the nearest integer value. Syntax Following is the syntax for converting a double to Int64 − long result = Convert.ToInt64(doubleValue); Parameters doubleValue − A double-precision floating-point number to be converted. Return Value Returns a ...

Read More

How do you use 'foreach' statement for accessing array elements in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 205 Views

The foreach statement in C# provides a simple way to iterate through all elements in an array without needing to manage index variables. Unlike a traditional for loop, foreach automatically accesses each element in sequence. Syntax Following is the syntax for using foreach with arrays − foreach (dataType variable in arrayName) { // code to process each element } The foreach loop automatically iterates through each element, assigning the current element's value to the specified variable. Using foreach with Arrays Example using System; class MyArray { ...

Read More

UInt16.Equals Method in C# with Examples

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 190 Views

The UInt16.Equals() method in C# returns a value indicating whether this instance is equal to a specified object or UInt16. This method provides two overloads: one for comparing with any object, and another specifically for comparing with another ushort value. Syntax Following are the two overloaded syntax forms − public override bool Equals (object ob); public bool Equals (ushort ob); Parameters ob (first overload) − An object to compare to this instance. ob (second overload) − The 16-bit unsigned integer to compare to this instance. Return Value Returns true ...

Read More

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 836 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 159 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
Showing 8391–8400 of 25,466 articles
« Prev 1 838 839 840 841 842 2547 Next »
Advertisements