Server Side Programming Articles

Page 783 of 2109

Generics vs non-generics in C#

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

There are two main types of collections in C#: generic collections and non-generic collections. The primary difference lies in type safety, performance, and how they handle different data types. Generic Collections Generic collections are type-safe and hold elements of the same data type. They provide better performance as they avoid boxing and unboxing operations for value types. Key Features Type Safety: Compile-time type checking prevents runtime errors Better Performance: No boxing/unboxing for value types IntelliSense Support: Better code completion and error detection Common Generic Collections List − Dynamic array of type ...

Read More

Why do we use internal keyword in C#?

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

The internal keyword in C# is an access modifier that provides assembly-level access. It allows class members to be accessible within the same assembly but restricts access from other assemblies, making it ideal for creating APIs that should only be used internally within your project. Syntax Following is the syntax for declaring internal members − internal class ClassName { // class accessible within assembly only } class MyClass { internal int field; // field accessible within assembly ...

Read More

How to compare two tuples in C#?

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

Tuple comparison was introduced in C# 7.3, allowing you to easily compare two tuples using equality operators. Tuples are compared element-wise, meaning each corresponding element in both tuples must be equal for the tuples to be considered equal. Syntax Following is the syntax for comparing tuples using the equality operator − bool result = tuple1 == tuple2; You can also use the inequality operator − bool result = tuple1 != tuple2; How Tuple Comparison Works Tuple comparison in C# follows these rules: Tuples must have the same ...

Read More

Why does the indexing start with zero in C# arrays?

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

In C#, array indexing starts at zero because arrays are fundamentally based on memory addressing and offset calculations. This design choice has deep roots in computer science and provides both efficiency and logical consistency. When an array is created, it occupies a contiguous block of memory. The array name acts as a pointer to the first element's memory address, and accessing elements involves calculating offsets from this base address. Memory Layout and Addressing Consider an integer array with 5 elements stored in memory. Since each int occupies 4 bytes, the memory layout would look like this − ...

Read More

How are values assigned to arrays in C#?

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

Declaring an array does not initialize the array in memory. When the array variable is initialized, you can assign values to the array using several different approaches in C#. Array is a reference type, so you need to use the new keyword to create an instance of the array. There are multiple ways to assign values to arrays, each with its own syntax and use cases. Syntax Following is the syntax for declaring and initializing arrays − // Declaration with size datatype[] arrayName = new datatype[size]; // Assignment using index arrayName[index] = value; ...

Read More

How to use Remove, RemoveAt, RemoveRange methods in C# list collections?

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

C# provides several methods to remove elements from List collections. The Remove() method removes the first occurrence of a specific value, RemoveAt() removes an element at a specific index, and RemoveRange() removes multiple consecutive elements. Syntax Following is the syntax for the three removal methods − // Remove by value (first occurrence) bool Remove(T item) // Remove by index void RemoveAt(int index) // Remove range of elements void RemoveRange(int index, int count) Parameters Remove(T item): The item to remove from the list. Returns true if item is found and removed. ...

Read More

What is the difference between a list and an array in C#?

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

An array stores a fixed-size sequential collection of elements of the same type, whereas a list is a generic collection that can dynamically resize during runtime. Understanding the differences between arrays and lists is crucial for choosing the right data structure for your C# applications. Syntax Following is the syntax for declaring and initializing an array − dataType[] arrayName = new dataType[size]; dataType[] arrayName = {value1, value2, value3}; Following is the syntax for declaring and initializing a list − List listName = new List(); List listName = new List {value1, value2, value3}; ...

Read More

final, finally and finalize in C#

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

In C#, the terms final, finally, and finalize serve different purposes. While final doesn't exist in C#, finally and finalize are crucial concepts for exception handling and resource cleanup respectively. final (sealed in C#) C# does not have a final keyword like Java. Instead, C# uses the sealed keyword to achieve similar functionality − public sealed class SealedClass { // cannot be inherited } public override sealed void SealedMethod() { // cannot be overridden further } The sealed keyword prevents overriding of methods or inheritance of classes. ...

Read More

Streams and Byte Streams in C#

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

A file is a collection of data stored in a disk with a specific name and a directory path. When a file is opened for reading or writing, it becomes a stream. Streams in C# provide a unified interface for reading and writing data, whether it's from files, memory, or network connections. The type of streams includes − Byte Streams − They handle raw binary data and include Stream, FileStream, MemoryStream, and BufferedStream. Character Streams − They handle text data and include TextReader, TextWriter, StreamReader, StreamWriter, and other text-based streams. Byte ...

Read More

String format for DateTime in C#

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

The String.Format method in C# provides powerful formatting capabilities for DateTime objects. You can use various format specifiers to display dates and times in different formats, from simple year displays to complex custom patterns. Syntax Following is the syntax for formatting DateTime using String.Format − String.Format("{0:format_specifier}", dateTimeObject) Common format specifiers include − y − Year (1 digit minimum) yy − Year (2 digits) yyyy − Year (4 digits) M − Month (1-12) MM − Month (01-12) MMM − Month abbreviation (Jan, Feb, etc.) MMMM − Full month name (January, February, etc.) d ...

Read More
Showing 7821–7830 of 21,090 articles
« Prev 1 781 782 783 784 785 2109 Next »
Advertisements