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
Csharp Articles
Page 100 of 196
What are key-based I/O collections in C#?
Key-based I/O collections in C# are collections that store data as key-value pairs, where you can access values using their associated keys. The primary example of this is the SortedList class, which maintains elements in sorted order based on the keys. Syntax Following is the syntax for declaring a generic SortedList − SortedList listName = new SortedList(); Following is the syntax for adding key-value pairs − listName.Add(key, value); listName[key] = value; // alternative syntax Key Features of SortedList Stores key-value pairs sorted by keys in ascending order ...
Read MoreWhat are identifiers in C#?
An identifier is a name used to identify a class, variable, function, or any other user-defined item in C#. Identifiers are fundamental building blocks that allow developers to name and reference different elements in their code. Rules for Naming Identifiers The basic rules for naming identifiers in C# are as follows − A name must begin with a letter or underscore that could be followed by a sequence of letters, digits (0-9), or underscores. The first character in an identifier cannot be a digit. It must not contain any embedded space or special ...
Read MoreWhat are dynamic data types in C#?
The dynamic data type in C# allows you to store any type of value in a variable. Unlike other data types, type checking for dynamic variables occurs at runtime rather than compile-time, providing flexibility but requiring careful handling to avoid runtime errors. Syntax Following is the syntax for declaring a dynamic variable − dynamic = value; Basic Dynamic Variable Declaration Example using System; class Program { public static void Main() { dynamic val1 = 100; ...
Read MoreWay to increment a character in C#
In C#, you can increment a character by using the increment operator ++. When you increment a character, it moves to the next character in the ASCII table sequence. Syntax Following is the syntax for incrementing a character − char ch = 'K'; ch++; // moves to next ASCII character You can also use the compound assignment operator − ch += 1; // equivalent to ch++ How It Works Characters in C# are stored as numeric values based on their ASCII or Unicode code points. When you ...
Read MoreWays to print escape characters in C#
The following are the escape characters in C# and the display column suggests how to use and print them in C# − Escape Character Description Pattern Display \a Matches a bell character, \u0007. \a "\u0007" in "Warning!" + '\u0007' \b In a character class, matches a backspace, \u0008. [\b]{3, } "\b\b\b\b" in "\b\b\b\b" \t Matches a tab, \u0009. (\w+)\t "Name\t", "Addr\t" in "Name\tAddr\t" \r Matches a carriage return, \u000D. (\r is not equivalent to the newline character, .) \r(\w+) "\rHello" in "\r\HelloWorld." \v Matches ...
Read MoreWay to read input from console in C#
The Console.ReadLine() method is the primary way to read input from the console in C#. This method reads a complete line of text from the console and returns it as a string. Since all console input is received as text, you need to convert it to the appropriate data type when working with numbers or other non-string values. Syntax Following is the syntax for reading console input − string input = Console.ReadLine(); For converting string input to other data types − int number = Convert.ToInt32(input); ...
Read MoreWhat are integer literals in C#?
An integer literal in C# is a constant numeric value written directly in the code. Integer literals can be decimal (base 10) or hexadecimal (base 16) constants. A prefix specifies the base: 0x or 0X for hexadecimal, with no prefix for decimal. They can also have suffixes like U for unsigned and L for long. Syntax Following is the syntax for different types of integer literals − // Decimal literals 123 200L // long 456U // unsigned int 789UL // unsigned long // Hexadecimal literals 0xFF ...
Read MoreWhat are file operations in C#?
File operations in C# allow you to work with files and directories on the file system. These operations include creating, opening, reading, writing, appending, and deleting files. The System.IO namespace provides comprehensive classes and methods for file handling. The FileStream class is the primary class for file operations in C#. It provides low-level access to files and derives from the abstract Stream class. This class enables reading from, writing to, and closing files efficiently. Syntax To create a FileStream object, use the following syntax − FileStream fileStream = new FileStream(fileName, FileMode, FileAccess, FileShare); ...
Read MoreWhat are mixed arrays in C#?
Mixed arrays in C# refer to arrays that can store elements of different data types. They were historically used as a combination of multi-dimensional arrays and jagged arrays, but this terminology is largely obsolete in modern C#. Instead, we use object[] arrays or collections to achieve similar functionality. Note − The traditional "mixed arrays" concept became obsolete after .NET 4.0, as modern C# provides better alternatives like generic collections and tuples. Syntax Following is the syntax for creating an array that can hold mixed data types − object[] arrayName = new object[] { value1, value2, ...
Read MoreWhat are objects in C#?
In C#, objects are instances of classes that represent real-world entities. An object is created from a class blueprint and contains actual data and behavior. Objects allow you to access and manipulate the members (fields, properties, and methods) defined in a class. To access class members through an object, you use the dot (.) operator. This operator connects the object name with the member name, enabling you to set values, call methods, and interact with the object's functionality. Syntax Following is the syntax for creating an object and accessing its members − ClassName objectName = ...
Read More