Articles on Trending Technologies

Technical articles with clear explanations and examples

Object Initializer in C#

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

An object initializer in C# allows you to initialize an object's properties or fields at the time of object creation without explicitly calling a constructor with parameters. This feature provides a more readable and concise way to create and initialize objects. Object initializers use curly braces {} to assign values to accessible properties or fields immediately after creating the object instance. Syntax Following is the basic syntax for object initializers − ClassName objectName = new ClassName() { PropertyName1 = value1, PropertyName2 = value2, ...

Read More

Type.GetEnumValues() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 432 Views

The Type.GetEnumValues() method in C# returns an array containing the values of all constants in an enumeration type. This method is useful when you need to iterate through all possible values of an enum or perform operations on the entire set of enum values. Syntax Following is the syntax for the GetEnumValues() method − public virtual Array GetEnumValues(); Return Value Returns an Array that contains the values of the constants in the current enumeration type. The elements of the array are sorted by the binary values of the enumeration constants. Using GetEnumValues() ...

Read More

C# Program to perform Currency Conversion

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

Currency conversion is a common programming task that involves multiplying an amount by an exchange rate. In C#, we can create simple currency conversion programs using basic arithmetic operations. A currency converter takes an amount in one currency and converts it to another currency using the current exchange rate. The formula is: Converted Amount = Original Amount × Exchange Rate. Syntax Following is the basic syntax for currency conversion − double convertedAmount = originalAmount * exchangeRate; Where variables are declared as − double originalAmount, convertedAmount, exchangeRate; Using Simple Currency ...

Read More

File Searching using C#

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

File searching in C# allows you to programmatically locate and examine files within directories using the System.IO namespace. The DirectoryInfo and FileInfo classes provide powerful methods to search, filter, and retrieve detailed information about files and directories. Syntax Following is the syntax for creating a DirectoryInfo object and searching files − DirectoryInfo directory = new DirectoryInfo(@"path\to\directory"); FileInfo[] files = directory.GetFiles(); Following is the syntax for searching files with specific patterns − FileInfo[] files = directory.GetFiles("*.txt"); // Text files only FileInfo[] files = directory.GetFiles("*", SearchOption.AllDirectories); // ...

Read More

Month ("M", "m") Format Specifier in C#

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

The Month ("M", "m") format specifier in C# represents a custom date and time format string that displays the month and day portions of a date. This format specifier is defined by the current DateTimeFormatInfo.MonthDayPattern property and typically follows the pattern MMMM dd. Syntax Following is the syntax for using the Month format specifier − dateTime.ToString("M") dateTime.ToString("m") The custom format string pattern is − MMMM dd Using Month Format Specifier Basic Example using System; using System.Globalization; class Demo { static void Main() ...

Read More

C# program to split the Even and Odd integers into different arrays

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

In C#, you can split an array of integers into separate arrays for even and odd numbers by checking if each element is divisible by 2. This technique is useful for data organization and filtering operations. How It Works The modulo operator (%) is used to determine if a number is even or odd. When a number is divided by 2, if the remainder is 0, the number is even; otherwise, it's odd. Even vs Odd Number Detection Even Numbers num % 2 == 0 ...

Read More

How to compile unsafe code in C#?

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

Unsafe code in C# allows direct memory manipulation using pointers, which bypasses the .NET garbage collector's safety mechanisms. To compile unsafe code, you need to enable unsafe context compilation through specific compiler settings. Command-Line Compilation For compiling unsafe code using the command-line compiler, you must specify the /unsafe switch − csc /unsafe filename.cs For example, to compile a program named one.cs containing unsafe code − csc /unsafe one.cs Visual Studio IDE Configuration In Visual Studio, you need to enable unsafe code compilation in the project properties. Follow these steps ...

Read More

Short Time ("t") Format Specifier in C#

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

The Short Time format specifier ("t") in C# is a standard date and time format specifier that displays only the time portion of a DateTime in a short format. It excludes the date and seconds, showing only hours and minutes along with the AM/PM designator for 12-hour formats. The "t" format specifier is defined by the DateTimeFormatInfo.ShortTimePattern property of the current culture. Different cultures may display the time differently based on their regional settings. Syntax Following is the syntax for using the short time format specifier − DateTime.ToString("t") DateTime.ToString("t", CultureInfo) The underlying custom ...

Read More

C# program to accept two integers and return the remainder

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

The remainder operation in C# finds the leftover value after dividing one integer by another. The modulus operator (%) is used to calculate the remainder when the first number is divided by the second number. Syntax Following is the syntax for calculating remainder using the modulus operator − int remainder = dividend % divisor; Where dividend is the number being divided and divisor is the number by which we divide. Using Basic Modulus Operation The simplest way to find the remainder is using the modulus operator directly − using System; ...

Read More

What are the different types of conditional statements supported by C#?

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

Conditional statements in C# allow programs to execute different code blocks based on specified conditions. These statements evaluate boolean expressions and direct program flow accordingly, enabling dynamic decision-making in applications. Types of Conditional Statements Statement Description if statement Executes a block of code when a boolean expression is true. if...else statement Executes one block if the condition is true, another if false. nested if statements Uses one if or else if statement inside another for complex conditions. switch statement Tests a variable against multiple values ...

Read More
Showing 11441–11450 of 61,303 articles
Advertisements