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 by Chandu yadav
Page 12 of 81
What does Array.IsFixedSize property of array class do in C# ?
The IsFixedSize property of the ArrayList class is used to determine whether an ArrayList has a fixed size. When IsFixedSize returns true, you cannot add or remove elements, but you can still modify existing elements. When it returns false, the ArrayList can grow or shrink dynamically. Regular ArrayLists created with the default constructor always return false for IsFixedSize because they can dynamically resize. However, you can create fixed-size wrappers using ArrayList.FixedSize() method. Syntax Following is the syntax to check the IsFixedSize property − bool isFixed = arrayList.IsFixedSize; Following is the syntax to create ...
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 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 MoreSorting a HashMap according to keys in C#
In C#, the equivalent of Java's HashMap is the Dictionary class, which stores key-value pairs. Sorting a Dictionary by keys requires extracting the keys, sorting them, and then accessing the values in the sorted order. Syntax Following is the syntax for creating and sorting a Dictionary by keys − Dictionary dict = new Dictionary(); // Sort keys using LINQ var sortedByKeys = dict.OrderBy(x => x.Key); // Or extract and sort keys manually var keys = dict.Keys.ToList(); keys.Sort(); Using LINQ OrderBy Method The most efficient way to sort a Dictionary by keys ...
Read MoreC# int.Parse Vs int.TryParse Method
The int.Parse and int.TryParse methods in C# are used to convert string representations of numbers to integers. The key difference lies in how they handle conversion failures: int.Parse throws an exception when the string cannot be converted, while int.TryParse returns a boolean value indicating success or failure. Syntax Following is the syntax for int.Parse method − int result = int.Parse(string); Following is the syntax for int.TryParse method − bool success = int.TryParse(string, out int result); Using int.Parse Method The int.Parse method directly converts a valid string to an integer. ...
Read MoreWhat is garbage collection in C#?
The garbage collector (GC) in C# is an automatic memory management system that handles the allocation and release of memory for managed objects. It eliminates the need for manual memory management, preventing memory leaks and reducing programming errors. The garbage collector operates on the managed heap, where all reference type objects are stored. When objects are no longer referenced by the application, the GC automatically reclaims their memory space. How Garbage Collection Works Garbage Collection Process Object Created Memory Low ...
Read MoreWhat is the difference between list and dictionary in C#?
A List and Dictionary are both generic collections in C#, but they serve different purposes. A List stores elements in a sequential order with index-based access, while a Dictionary stores key-value pairs for fast lookups. Understanding when to use each collection type is crucial for writing efficient C# applications. Lists are ideal for ordered data where you need to access elements by position, while dictionaries are perfect for mapping relationships and quick key-based retrieval. Syntax Following is the syntax for creating a List − List listName = new List(); // or with initialization List listName ...
Read MoreDifferent ways of Reading a file in C#
There are several ways to read files in C#, each suited for different scenarios. C# provides various classes in the System.IO namespace for file operations, including reading text files, binary files, and handling different data types efficiently. Using StreamReader for Text Files The StreamReader class is the most common way to read text files line by line. It provides efficient reading with proper resource management using the using statement − using System; using System.IO; class Program { static void Main(string[] args) { // ...
Read MoreValue parameters vs Reference parameters vs Output Parameters in C#
In C#, there are three ways to pass parameters to methods: value parameters, reference parameters, and output parameters. Each mechanism behaves differently in terms of how data is passed and whether changes affect the original variables. Syntax Following are the syntax forms for the three parameter types − // Value parameter (default) public void Method(int value) { } // Reference parameter public void Method(ref int value) { } // Output parameter public void Method(out int value) { } Value Parameters Value parameters copy the actual value of an argument into the ...
Read MoreCompilation and Execution of a C# Program
To compile and execute a program in C#, you can use several methods depending on your development environment. The most common approaches include using Visual Studio IDE, command-line tools, or online compilers. Using Visual Studio IDE In Microsoft Visual Studio IDE, compilation and execution is straightforward − Click the Run button or press F5 key to build and execute the project. Visual Studio automatically compiles your code and runs the executable. Any compilation errors will appear in the Error List window. Command-Line Compilation You can compile C# programs using the command-line C# compiler ...
Read More