Server Side Programming Articles

Page 772 of 2109

How to use C# FileStream class?

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

The FileStream class in C# provides a stream for file operations such as reading from and writing to files. It is part of the System.IO namespace and allows byte-level access to files on the file system. FileStream is useful when you need direct control over file operations, especially for binary data or when working with large files efficiently. Syntax Following is the basic syntax for creating a FileStream object − FileStream fileStream = new FileStream(path, FileMode, FileAccess); The FileMode parameter specifies how the file should be opened − FileMode.OpenOrCreate // ...

Read More

How to calculate the Size of Folder using C#?

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

To calculate the size of a folder in C#, you need to traverse through all files in the folder and its subdirectories, then sum up their sizes. The DirectoryInfo class provides methods to enumerate files and directories, making this task straightforward. Syntax Following is the syntax for getting folder information and enumerating files − DirectoryInfo info = new DirectoryInfo(@"C:\FolderPath"); long size = info.EnumerateFiles("*", SearchOption.AllDirectories).Sum(file => file.Length); Using DirectoryInfo for Simple Folder Size The most basic approach uses DirectoryInfo.EnumerateFiles() with SearchOption.AllDirectories to include all subdirectories − using System; using System.IO; using System.Linq; ...

Read More

How to calculate Power of a number using recursion in C#?

George John
George John
Updated on 17-Mar-2026 1K+ Views

To calculate power of a number using recursion in C#, we use the mathematical principle that n^p = n × n^(p-1). The recursive function calls itself with a reduced power until it reaches the base case. Syntax Following is the syntax for a recursive power function − static long Power(int number, int power) { if (power == 0) { return 1; // base case } return number * Power(number, power - 1); // recursive ...

Read More

What are pointers in C#?

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

A pointer is a variable that stores the memory address of another variable. Unlike reference types, pointers provide direct access to memory locations, making them powerful but potentially unsafe. In C#, pointers can only be used within unsafe code blocks or methods. This restriction exists because pointers bypass .NET's garbage collection and type safety mechanisms. Syntax Following is the syntax for declaring a pointer − type *pointerName; Following is the syntax for getting the address of a variable − type *pointer = &variable; Following is the syntax for dereferencing ...

Read More

How to pass pointers as parameters to methods in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

To pass pointers as parameters to methods in C#, you need to use unsafe code and pointer syntax. Pointers allow direct memory manipulation and can be passed to methods for operations like swapping values or modifying data directly in memory. C# requires the unsafe keyword when working with pointers, and your project must be configured to allow unsafe code compilation. Syntax Following is the syntax for declaring a method that accepts pointer parameters − public unsafe void MethodName(int* pointer1, int* pointer2) { // pointer operations } Following is the ...

Read More

What is method overloading in C#?

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

Method overloading in C# allows you to define multiple methods with the same name but different parameters. This enables you to create methods that perform similar operations but accept different types or numbers of arguments. Method overloading can be achieved by changing the number of parameters, the data types of parameters, or the order of parameters. The compiler determines which method to call based on the arguments passed at runtime. Syntax Following is the syntax for method overloading − public returnType MethodName(type1 param1) { } public returnType MethodName(type1 param1, type2 param2) { } public returnType ...

Read More

What are the main parts of a C# program?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

The main parts of a C# program include − Namespace declaration A class Class methods Class attributes A Main method Statements and Expressions Comments Understanding these components is essential for writing effective C# programs. Each part serves a specific purpose in organizing and executing your code. Basic C# Program Structure The following example demonstrates a simple C# program with all the essential parts − using System; namespace Demo { class Program { // Class attribute (field) ...

Read More

What is compile time polymorphism in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

Compile-time polymorphism in C# is a type of polymorphism where the method to be called is determined during compilation rather than at runtime. It is also known as static polymorphism or early binding, because the method binding occurs at compile time. C# provides two main techniques to implement compile-time polymorphism − Method Overloading and Operator Overloading. The compiler resolves which method to call based on the method signature (method name, number of parameters, and parameter types). Compile-time Polymorphism Method Resolution at Compile Time Compiler determines which method ...

Read More

What is composition in C#?

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

Composition in C# is a design principle where one class contains an instance of another class as a private member, creating a "has-a" relationship. In composition, the contained object (child) cannot exist independently of the container object (parent). When the parent object is destroyed, the child object is also destroyed, establishing a strong ownership relationship. Composition represents a part-of relationship, which is a special type of association that implies strong coupling between objects. Syntax Following is the basic syntax for implementing composition in C# − public class ContainedClass { // properties and ...

Read More

What is a parameterized constructor in C# programs?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 3K+ Views

A parameterized constructor in C# is a constructor that accepts parameters to initialize an object with specific values at the time of creation. This allows you to set initial values for the object's fields or properties during instantiation, making object creation more flexible and efficient. Syntax Following is the syntax for declaring a parameterized constructor − public ClassName(dataType parameter1, dataType parameter2) { // initialization code this.field1 = parameter1; this.field2 = parameter2; } To create an object using a parameterized constructor − ClassName objectName ...

Read More
Showing 7711–7720 of 21,090 articles
« Prev 1 770 771 772 773 774 2109 Next »
Advertisements