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
Server Side Programming Articles
Page 774 of 2109
How to determine if the string has all unique characters using C#?
To determine if a string has all unique characters, you need to check if any character appears more than once. This can be accomplished using several approaches in C#, from simple nested loops to more efficient data structures like HashSet. Using Nested Loop Approach The basic approach involves comparing each character with every other character in the string − using System; class Program { public static bool HasUniqueCharacters(string val) { for (int i = 0; i < val.Length - 1; i++) { ...
Read MoreHow to use ReadKey() method of Console class in C#?
The Console.ReadKey() method in C# reads the next character or function key pressed by the user. This method is commonly used to pause program execution until the user presses a key, which is particularly useful when running console applications from Visual Studio to prevent the console window from closing immediately. Syntax The Console.ReadKey() method has two overloads − public static ConsoleKeyInfo ReadKey(); public static ConsoleKeyInfo ReadKey(bool intercept); Parameters intercept (optional): A boolean value that determines whether to display the pressed key in the console. If true, the key is not displayed; if ...
Read MoreInteger literals vs Floating point literals in C#
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 MoreHashSet in C#
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 MoreWhat are the C++ features missing in C#?
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 MoreWhat are circular references in C#?
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 MoreWhat is the use of 'Using' statement in C#?
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 MoreWhat are string literals in C#?
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 MoreWhat are floating point literals in C#?
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 MoreWhat are I/O classes in C#?
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