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
Object Initializer in C#
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 MoreType.GetEnumValues() Method in C#
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 MoreC# Program to perform Currency Conversion
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 MoreFile Searching using C#
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 MoreMonth ("M", "m") Format Specifier in C#
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 MoreC# program to split the Even and Odd integers into different arrays
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 MoreHow to compile unsafe code in C#?
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 MoreShort Time ("t") Format Specifier in C#
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 MoreC# program to accept two integers and return the remainder
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 MoreWhat are the different types of conditional statements supported by C#?
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