Csharp Articles

Page 99 of 196

Integer literals vs Floating point literals in C#

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

In C#, literals are fixed values written directly in the source code. There are two main categories of numeric literals: integer literals for whole numbers and floating-point literals for decimal numbers. Understanding the difference between these literals is essential for proper variable declaration and avoiding compilation errors. Integer Literals An integer literal represents a whole number without a decimal point. Integer literals can be decimal (base 10) or hexadecimal (base 16). A prefix specifies the base: 0x or 0X for hexadecimal, with no prefix for decimal. Syntax decimal_literal // 10, 100, ...

Read More

HashSet in C#

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

A HashSet in C# is a high-performance collection that stores unique elements and automatically eliminates duplicates. It provides fast lookups, insertions, and deletions with O(1) average time complexity, making it ideal for scenarios where you need to maintain a collection of distinct values. HashSet is part of the System.Collections.Generic namespace and implements the ISet interface, providing mathematical set operations like union, intersection, and difference. Syntax Following is the syntax for declaring and initializing a HashSet − HashSet hashSetName = new HashSet(); You can also initialize it with an existing collection − ...

Read More

What are the C++ features missing in C#?

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

C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. While C# and C++ share some similarities, there are several key features present in C++ that are either missing or implemented differently in C#. C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms and provides more direct hardware control compared to C#. Key C++ Features Missing in C# Multiple Inheritance C++ supports multiple inheritance, allowing a class to inherit from multiple base ...

Read More

What are circular references in C#?

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

A circular reference in C# occurs when two or more objects reference each other directly or indirectly, creating a dependency loop. This can cause memory leaks and prevent proper garbage collection if not handled correctly. The .NET garbage collector is designed to detect and handle circular references automatically. It uses a mark-and-sweep algorithm that starts from root objects (like static variables and local variables) and marks all reachable objects, then collects unmarked objects even if they have circular references. Understanding Circular References Circular references typically occur in parent-child relationships, linked lists, or complex object graphs where objects ...

Read More

What is the use of 'Using' statement in C#?

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

The using statement in C# is used for automatic resource management and memory cleanup. It ensures that resources are properly disposed of when they are no longer needed, even if an exception occurs. The using statement works with objects that implement the IDisposable interface. The main goal of the using statement is to manage resources and automatically release them when the code block completes execution. This is particularly useful for file operations, database connections, and other system resources that need explicit cleanup. Syntax Following is the syntax for the using statement − using (ResourceType resource ...

Read More

What are string literals in C#?

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

String literals in C# are constant string values enclosed in double quotes "" or prefixed with @"" for verbatim strings. A string literal contains characters that can include plain text, escape sequences, and Unicode characters. Types of String Literals C# supports several types of string literals − Regular String Literals: Enclosed in double quotes with escape sequences Verbatim String Literals: Prefixed with @ symbol, allowing multi-line strings and literal backslashes Raw String Literals: (C# 11+) Use triple quotes """ for complex strings Syntax Following are the different syntaxes for string literals − ...

Read More

What are floating point literals in C#?

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

A floating-point literal in C# represents a decimal number that can contain a fractional part. It consists of an integer part, a decimal point, a fractional part, and optionally an exponent part. You can represent floating point literals in either decimal form or exponential form. Syntax Following are the different forms of floating-point literal syntax − // Decimal form 123.45 0.5678 // Exponential form 1.23E+2 // 1.23 × 10² 4.56e-3 // 4.56 × 10⁻³ // With type suffixes 3.14f // float 2.718 ...

Read More

What are I/O classes in C#?

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

The System.IO namespace in C# provides a comprehensive collection of classes for performing input/output operations. These classes enable you to work with files, directories, streams, and other data sources efficiently. I/O classes in C# are categorized into several groups based on their functionality − File and Directory Classes These classes provide static methods for basic file and directory operations − using System; using System.IO; class Program { public static void Main() { // File class example string fileName = ...

Read More

What are generic collections in C#?

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

Generic collections in C# are type-safe collections that allow you to specify the type of elements at compile time. They provide better performance, type safety, and IntelliSense support compared to non-generic collections like ArrayList and Hashtable. The most commonly used generic collections include List, Dictionary, SortedList, Queue, and Stack. These are part of the System.Collections.Generic namespace. Syntax Following is the syntax for declaring generic collections − List listName = new List(); Dictionary dictName = new Dictionary(); SortedList sortedListName = new SortedList(); Where T, TKey, and TValue are type parameters that specify the actual ...

Read More

What are generic delegates in C#?

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

Generic delegates in C# allow you to create delegate types with type parameters, providing flexibility to work with different data types without defining separate delegate declarations for each type. The .NET Framework provides several built-in generic delegates in the System namespace that eliminate the need for custom delegate definitions in most scenarios. Syntax Following is the syntax for declaring a custom generic delegate − delegate TResult DelegateName(T parameter); Built-in generic delegates use these syntaxes − Action actionDelegate = method; // void return type Func funcDelegate = method; // ...

Read More
Showing 981–990 of 1,951 articles
« Prev 1 97 98 99 100 101 196 Next »
Advertisements