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
How to get complete drive information using C#?
Drive information of an Operating System includes key details about storage drives such as drive name, volume label, free space, total size, drive format, and drive type. In C#, you can retrieve this information using the DriveInfo class from the System.IO namespace. Syntax Following is the syntax for creating a DriveInfo object and accessing its properties − DriveInfo driveInfo = new DriveInfo("DriveLetter"); string name = driveInfo.Name; long freeSpace = driveInfo.AvailableFreeSpace; DriveType type = driveInfo.DriveType; DriveInfo Properties Property Description Name Gets the drive name (e.g., "C:") ...
Read MorePrint first letter of each word in a string using C# regex
In C#, you can use regular expressions to extract the first letter of each word from a string. This technique uses the Regex.Matches() method with a specific pattern to identify word boundaries and capture the initial characters. Syntax The regular expression pattern to match the first letter of each word is − @"\b[a-zA-Z]" Where − \b − represents a word boundary [a-zA-Z] − matches any single letter (uppercase or lowercase) The Regex.Matches() method syntax − MatchCollection matches = Regex.Matches(inputString, pattern); How It Works ...
Read MoreRepresent Int32 as a Binary String in C#
To represent an Int32 as a binary string in C#, use the Convert.ToString() method with base 2 as the second parameter. This method converts the integer's binary representation into a readable string format. Int32 represents a 32-bit signed integer that can hold values from -2, 147, 483, 648 to 2, 147, 483, 647. Syntax Following is the syntax for converting an integer to binary string − Convert.ToString(value, 2) Parameters value − The integer value to convert to binary representation 2 − The base for binary number system ...
Read MoreStatic binding vs Dynamic binding in C#
Polymorphism can be static or dynamic. In static polymorphism, the method to be called is determined at compile time. In dynamic polymorphism, the decision is made at runtime based on the actual object type. Static Binding (Compile-Time Polymorphism) Static binding links a function with an object during compile time. It is also called early binding. This is achieved through method overloading and operator overloading. Static Binding Process Source Code Method calls Compiler Resolves calls ...
Read MoreHow to read inputs as integers in C#?
To read inputs as integers in C#, you need to first read the input as a string using Console.ReadLine() and then convert it to an integer using methods like Convert.ToInt32() or int.Parse(). The process involves two steps: reading the user input as a string and converting it to an integer data type for mathematical operations. Syntax Following is the basic syntax for reading integer input − string input = Console.ReadLine(); int number = Convert.ToInt32(input); You can also use int.Parse() method − int number = int.Parse(Console.ReadLine()); Using Convert.ToInt32() Method ...
Read MoreConvert a ValueTuple to a Tuple in C#
In C#, you can easily convert a ValueTuple to a Tuple using the ToTuple() method. ValueTuples are value types introduced in C# 7.0, while Tuples are reference types that have been available since earlier versions of C#. Note − For .NET Framework projects, you may need to add the System.ValueTuple NuGet package to use ValueTuple features. Syntax Following is the syntax for converting a ValueTuple to a Tuple using the ToTuple() method − var valueTuple = (value1, value2, value3); Tuple tuple = valueTuple.ToTuple(); Converting ValueTuple to Tuple Example using System; ...
Read MoreDifference between Abstract Class and Interface in C#
Both abstract classes and interfaces in C# define contracts for derived classes to implement, but they serve different purposes and have distinct characteristics. An interface defines a contract with method signatures that implementing classes must provide, while an abstract class can provide both abstract methods and concrete implementations that derived classes inherit. Understanding the key differences helps you choose the right approach for your object-oriented design needs. Syntax Following is the syntax for declaring an interface − public interface IInterfaceName { void Method1(); int Property1 { get; ...
Read MoreDateTime.Add() Method in C#
The DateTime.Add() method in C# is used to return a new DateTime that adds the value of the specified TimeSpan to the value of this instance. This method allows you to add or subtract time intervals including days, hours, minutes, seconds, and milliseconds. Syntax Following is the syntax − public DateTime Add(TimeSpan value); Parameters value − A positive or negative TimeSpan that represents the time interval to add to the current DateTime instance. Return Value Returns a new DateTime object whose value is the sum of the ...
Read MoreC# Round-trip ("R") Format Specifier
The round-trip ("R") format specifier in C# ensures that a numeric value converted to a string can be parsed back into the same exact numeric value without any precision loss. This format specifier is supported for Single, Double, and BigInteger types. The "R" specifier is particularly useful when you need to serialize floating-point numbers to strings and then deserialize them back while maintaining perfect accuracy. Syntax Following is the syntax for using the round-trip format specifier − value.ToString("R") value.ToString("R", CultureInfo.InvariantCulture) How It Works The round-trip format specifier automatically determines the minimum number ...
Read MoreDifference between Boxing and Unboxing in C#
Boxing converts a value type to an object type, whereas unboxing converts an object type back to the value type. These operations are fundamental concepts in C# that involve moving data between the stack and heap memory. Boxing occurs implicitly when you assign a value type to an object variable, while unboxing requires explicit casting and can throw exceptions if the types don't match. Syntax Following is the syntax for boxing (implicit conversion) − object boxedValue = valueType; Following is the syntax for unboxing (explicit conversion) − ValueType unboxedValue = (ValueType)boxedObject; ...
Read More