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
File Objects in C#
The FileStream class in C# is used to create, read, write, and manipulate files. It provides low-level access to file operations and is part of the System.IO namespace. FileStream works with bytes, making it suitable for both text and binary files. Syntax Following is the syntax for creating a FileStream object − FileStream objectName = new FileStream(fileName, FileMode, FileAccess, FileShare); A simplified syntax for common scenarios − FileStream objectName = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); Parameters Parameter Description Common Values fileName Path and ...
Read MoreConvert.ToUInt32 Method in C#
The Convert.ToUInt32 method in C# converts a specified value to a 32-bit unsigned integer (uint). This method can convert various data types including strings, integers, floating-point numbers, and other numeric types to an unsigned 32-bit integer. The uint data type can hold values from 0 to 4, 294, 967, 295, making it suitable for scenarios where you need positive integers only with a larger range than regular int. Syntax Following are the common overloads of the Convert.ToUInt32 method − Convert.ToUInt32(string value) Convert.ToUInt32(int value) Convert.ToUInt32(double value) Convert.ToUInt32(object value) Parameters value − The ...
Read MoreC# Program to find whether the Number is Divisible by 2
A number is divisible by 2 if the remainder is 0 when the number is divided by 2. This is checked using the modulo operator (%) in C#, which returns the remainder of a division operation. Numbers divisible by 2 are called even numbers, while numbers not divisible by 2 are called odd numbers. Divisibility by 2 Check Even Numbers num % 2 == 0 Examples: 2, 4, 6, 8, 10 Odd Numbers num % 2 ...
Read MoreWhat does Array.Length property of array class do in C#?
The Array.Length property in C# is used to get the total number of elements in an array. This property returns an integer value representing the array's size, which is essential for array manipulation and iteration. Syntax Following is the syntax for using the Array.Length property − int length = arrayName.Length; Return Value The Length property returns an int value representing the total number of elements in the array. Using Array.Length with Array.CreateInstance The following example demonstrates how to use Array.Length with dynamically created arrays − using System; class ...
Read MoreHow to truncate a file in C#?
To truncate a file in C#, use the FileStream.SetLength method. This method allows you to change the size of a file by either reducing it (truncating) or expanding it to a specified length. Syntax Following is the syntax for the SetLength method − public override void SetLength(long value); Parameters value − A long representing the desired length of the stream in bytes. How It Works The behavior of SetLength depends on whether the new value is smaller or larger than the current file size − ...
Read MoreC# Enum Format Method
The Enum.Format method in C# converts the value of a specified enumerated type to its equivalent string representation according to the specified format. This method provides flexible formatting options including decimal, hexadecimal, and name representations. Syntax Following is the syntax for the Enum.Format method − public static string Format(Type enumType, object value, string format) Parameters enumType − The enumeration type of the value to convert. value − The value to convert. format − The output format to use. Common formats are "G" (name), "D" (decimal), "X" (hexadecimal), and "F" (name if defined, ...
Read MoreC# program to find the sum of digits of a number using Recursion
A recursive function calls itself with modified parameters until it reaches a base case. To find the sum of digits of a number using recursion, we extract the last digit using the modulus operator (%) and add it to the sum of remaining digits. Syntax Following is the syntax for a recursive function to sum digits − public int SumOfDigits(int number) { if (number == 0) { return 0; // base case } return (number % 10) + SumOfDigits(number / ...
Read MoreWhat does Array.LongLength property of array class do in C#?
The Array.LongLength property in C# gets a 64-bit integer (long) that represents the total number of elements in all dimensions of an array. This property is particularly useful when working with very large arrays that might exceed the range of a 32-bit integer. Syntax Following is the syntax for using the LongLength property − long totalElements = arrayName.LongLength; Return Value The property returns a long value representing the total number of elements across all dimensions of the array. Single-Dimensional Array Example For a single-dimensional array, LongLength returns the same value as ...
Read MoreWhat is a static class in C#?
A static class in C# is a class that cannot be instantiated and can only contain static members. Static classes are implicitly sealed, meaning they cannot be inherited, and they cannot contain instance constructors or non-static members. Static classes are useful for grouping related utility methods and constants that don't require object instantiation. They are loaded automatically by the .NET runtime when first referenced. Syntax Following is the syntax for declaring a static class − public static class ClassName { public static ReturnType MethodName() { ...
Read MoreInitialization vs Instantiation in C#
In C#, initialization and instantiation are two fundamental concepts that are often confused. Initialization refers to assigning a value to a variable when it is declared, while instantiation refers to creating a new object instance using the new keyword. Initialization Initialization is the process of assigning a value to a variable at the time of declaration. This can be done for value types, reference types, and collections − Value Type Initialization using System; class Program { public static void Main() { int val = 50; ...
Read More