Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Valid variant of Main() in C#
The Main method is the entry point for all C# programs. It defines what the class does when executed. When you run a C# application, the runtime looks for the Main method and begins execution from there. Syntax There are several valid variants of the Main method in C# − static void Main() static void Main(string[] args) static int Main() static int Main(string[] args) Parameters static − the object is not needed to access static members. The Main method must be static so the runtime can call it without creating an ...
Read MoreC# Program to split parts in a Windows directory
A Windows directory path consists of multiple parts separated by backslashes (\). In C#, you can split a directory path into its individual components using the Split() method with the backslash character as the delimiter. This technique is useful for extracting specific parts of a path, validating directory structures, or processing file paths programmatically. Syntax Following is the syntax for splitting a Windows directory path − string[] parts = directoryPath.Split(''); You can also use the verbatim string literal to define the path − string path = @"C:\Users\Documents\MyFile.txt"; Using Split() ...
Read MoreC# Program to convert a Byte value to an Int32 value
To convert a byte value to an int value in C#, you can use the Convert.ToInt32() method or implicit conversion. Since a byte (8-bit unsigned integer) can always fit within an int (32-bit signed integer), the conversion is straightforward and safe. An Int32 represents a 32-bit signed integer that can store values from -2, 147, 483, 648 to 2, 147, 483, 647, while a byte stores values from 0 to 255. Syntax Using Convert.ToInt32() method − int result = Convert.ToInt32(byteValue); Using implicit conversion − int result = byteValue; Using ...
Read MoreByte.CompareTo(Byte) Method in C#
The Byte.CompareTo(Byte) method in C# is used to compare the current byte instance to a specified 8-bit unsigned integer and returns an indication of their relative values. This method is useful for sorting operations and determining the relative ordering of byte values. Syntax Following is the syntax − public int CompareTo(byte value); Parameters value: An 8-bit unsigned integer to compare with the current instance. Return Value The method returns an integer that indicates the relative values of the compared instances: Less than zero: The current instance is less ...
Read MoreWhat are the escape sequences supported by C#?
Escape sequences in C# are special character combinations that start with a backslash (\) and represent characters that are difficult or impossible to type directly. These sequences allow you to include special characters like newlines, tabs, quotes, and control characters in your strings. Syntax Following is the syntax for escape sequences in C# − string text = "HelloWorld"; // represents a newline char tab = '\t'; // \t represents a tab character Common Escape Sequences ...
Read MoreMain thread vs child thread in C#
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 MoreC# Program to write a number in hexadecimal format
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 MoreC# Program to convert a Double value to an Int64 value
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 MoreHow do you use 'foreach' statement for accessing array elements in C#
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 MoreUInt16.Equals Method in C# with Examples
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