Server Side Programming Articles

Page 802 of 2109

Initialization vs Instantiation in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 5K+ Views

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

Comparison of double and float primitive types in C#

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

In C#, float and double are both floating-point data types used to store decimal numbers, but they differ significantly in precision, memory usage, and range. Understanding these differences is crucial for choosing the right data type for your applications. Syntax Following is the syntax for declaring float and double variables − float floatVariable = 3.14f; double doubleVariable = 3.14159265359; Note the f suffix for float literals and optional d suffix for double literals − float price = 19.99f; double pi = 3.14159265359d; // 'd' is optional for double Key Differences ...

Read More

Does declaring an array create an array in C#?

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

Declaring an array in C# does not create the actual array object in memory. Array declaration only creates a reference variable that can point to an array object. The array must be explicitly initialized using the new keyword to allocate memory and create the array instance. Array Declaration vs Array Creation Understanding the difference between declaration and creation is crucial for working with arrays in C# − Array Declaration vs Creation Declaration Only int[] arr; • Creates reference variable • No memory ...

Read More

Local Inner Class in C#

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

A nested class in C# is a class declared inside another enclosing class. The nested class is a member of its outer class and can access the outer class's private members, while the outer class cannot directly access the nested class's members without creating an instance. Nested classes provide better organization and encapsulation by grouping related functionality together. They are particularly useful when a class is only meaningful within the context of another class. Syntax Following is the syntax for declaring a nested class − class OuterClass { // outer class ...

Read More

C# ToEven property

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 158 Views

The ToEven property is a value in the MidpointRounding enumeration that implements banker's rounding. When a number falls exactly between two integers, it rounds to the nearest even number. This method reduces bias in calculations compared to always rounding up or down. Syntax Following is the syntax for using MidpointRounding.ToEven − decimal.Round(value, digits, MidpointRounding.ToEven) Math.Round(value, digits, MidpointRounding.ToEven) Parameters value − The number to be rounded digits − Number of decimal places in the return value MidpointRounding.ToEven − Rounds to the nearest even number when the value is exactly halfway between two numbers ...

Read More

How to open a plain text file in C#?

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

In C#, you can open and read a plain text file using the StreamReader class from the System.IO namespace. The StreamReader provides methods to read character data from a stream in a particular encoding. Syntax Following is the basic syntax for opening a text file with StreamReader − StreamReader sr = new StreamReader("filepath"); For proper resource management, use the using statement − using (StreamReader sr = new StreamReader("filepath")) { // Read file content } Using StreamReader to Read Text Files The most common approach is ...

Read More

Different ways of Reading a file in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 347 Views

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 More

How to open hidden file using C#?

George John
George John
Updated on 17-Mar-2026 782 Views

To open a hidden file in C#, you need to first make it visible by removing the hidden attribute, then read its contents, and optionally restore the hidden attribute afterward. Hidden files have the FileAttributes.Hidden attribute set, which prevents them from being displayed in normal file explorers. Syntax Following is the syntax for removing the hidden attribute from a file − FileInfo file = new FileInfo(filePath); file.Attributes &= ~FileAttributes.Hidden; Following is the syntax for restoring the hidden attribute − file.Attributes |= FileAttributes.Hidden; Using FileInfo to Remove Hidden Attribute The ...

Read More

What is the C# equivalent for the Java System.exit(0)?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 2K+ Views

The C# equivalent for Java's System.exit(0) is the Environment.Exit() method. This method terminates the current process and returns an exit code to the operating system, just like its Java counterpart. Syntax Following is the syntax for using Environment.Exit() − Environment.Exit(exitCode); Parameters exitCode − An integer value returned to the operating system. Use 0 to indicate successful termination, and non-zero values to indicate different error conditions. Exit Code Conventions Exit Code Meaning 0 Process completed successfully 1 General error ...

Read More

What is the C# equivalent of C++ friend keyword?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 3K+ Views

In C++, the friend keyword allows external functions or classes to access private and protected members of a class. C# does not have a direct equivalent to the friend keyword, but there are several approaches to achieve similar functionality. Understanding the friend Concept A friend function in C++ is defined outside a class but has access to all private and protected members of that class. While C# doesn't support this directly, it provides alternative mechanisms to control access between closely related classes. Using Nested Classes The closest equivalent to C++ friend functionality is using nested classes. ...

Read More
Showing 8011–8020 of 21,090 articles
« Prev 1 800 801 802 803 804 2109 Next »
Advertisements