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
Programming Articles
Page 74 of 2547
Gets or sets the value in HybridDictionary with specified key in C#
The HybridDictionary class in C# provides an indexer property that allows you to get or set values using a specified key. The HybridDictionary is part of the System.Collections.Specialized namespace and combines the benefits of both ListDictionary and Hashtable for optimal performance with small and large collections. Syntax Following is the syntax for getting or setting values in HybridDictionary using the indexer − // Getting a value object value = hybridDict[key]; // Setting a value hybridDict[key] = value; Parameters key − The key of the element to get or set. Can ...
Read MoreWhat does LINQ return when the results are empty in C#?
Language-Integrated Query (LINQ) is a set of technologies that integrates query capabilities directly into the C# language. When LINQ queries return no results, the behavior depends on which LINQ method you use. LINQ queries can be written for SQL Server databases, XML documents, ADO.NET Datasets, and any collection that supports IEnumerable or IEnumerable. Understanding what happens when queries return empty results is crucial for avoiding runtime exceptions. Common LINQ Methods and Empty Results LINQ Method Empty Result Behavior ToList() Returns an empty List ToArray() Returns an empty array ...
Read MoreHow to post data to specific URL using WebClient in C#?
The WebClient class in C# provides simple methods for sending and receiving data from web servers. It's particularly useful for posting data to specific URLs, making it easy to interact with Web APIs without complex HTTP handling. WebClient offers methods like UploadString, UploadData, and UploadValues for posting different types of data. While HttpClient is the modern alternative, WebClient remains useful for simple scenarios. Namespace and Assembly Namespace: System.Net Assembly: System.Net.WebClient.dll Syntax Following is the basic syntax for posting data using WebClient − using (WebClient client = new WebClient()) { ...
Read MoreBoolean.ToString(IFormatProvider) Method in C#
The Boolean.ToString(IFormatProvider) method in C# converts a Boolean value to its equivalent string representation. This method accepts an IFormatProvider parameter, though Boolean values are not culture-sensitive and always return "True" or "False" regardless of the culture specified. Syntax Following is the syntax for the Boolean.ToString(IFormatProvider) method − public string ToString(IFormatProvider provider); Parameters provider − An IFormatProvider object that provides culture-specific formatting information. This parameter is reserved but not used for Boolean values. Return Value Returns a string representation of the Boolean value. The method returns "True" for true values ...
Read MoreHow to write Regex for numbers only in C#?
Regular expressions (regex) are patterns used to match specific text formats. In C#, you can create regex patterns to validate that input contains only numbers. The System.Text.RegularExpressions.Regex class provides methods to test strings against these patterns. For numbers-only validation, you need to understand the key regex metacharacters and how to construct patterns that accept different numeric formats like integers, decimals, and negative numbers. Syntax Basic regex pattern for numbers only − Regex regex = new Regex(@"^[0-9]+$"); Pattern for numbers with optional decimal point − Regex regex = new Regex(@"^[0-9]+\.?[0-9]*$"); ...
Read MoreDouble.CompareTo Method in C# with Examples
The Double.CompareTo() method in C# compares the current double instance to another double value or object. It returns an integer that indicates whether the current value is less than, equal to, or greater than the compared value. Syntax Following are the two overloads of the Double.CompareTo() − public int CompareTo(double value); public int CompareTo(object value); Parameters value − A double-precision floating-point number or object to compare with the current instance. Return Value The method returns an integer with the following meaning − Less than ...
Read MoreHow do you get the file size in C#?
Getting the file size in C# can be accomplished using several methods. The most common approach is using the FileInfo class, which provides the Length property to retrieve the size of a file in bytes. You can also use static methods from the File class for quick operations without creating instances. The FileInfo class is part of the System.IO namespace and provides comprehensive file manipulation capabilities including size retrieval, creation dates, and access permissions. Syntax Using FileInfo class to get file size − FileInfo fileInfo = new FileInfo(filePath); long fileSize = fileInfo.Length; Using ...
Read MoreGet the type referenced by the specified type handle in C#
To get the type referenced by the specified type handle in C#, you use the Type.GetTypeFromHandle() method. This method takes a RuntimeTypeHandle and returns the corresponding Type object. Type handles provide a lightweight way to represent types at runtime and are commonly used in low-level reflection scenarios. Syntax Following is the syntax for getting a type handle and retrieving the type − RuntimeTypeHandle typeHandle = Type.GetTypeHandle(object); Type type = Type.GetTypeFromHandle(typeHandle); Parameters handle − The RuntimeTypeHandle structure that refers to the type. Return Value Returns the Type referenced by the ...
Read MoreHow to use Interface References in C#?
C# is an object-oriented programming language that offers a unique feature known as interfaces. They enable you to declare a collection of methods and properties that a class must implement without specifying the implementation details. The ability to write code that is independent of a class's implementation details is one of the main benefits of interfaces. Each object of any class that implements the interface can be referred to using an interface reference. As a result, it is simpler to switch between different class implementations without having to modify the code that utilizes the class. Syntax for ...
Read MoreDouble.Equals() Method in C# with Examples
The Double.Equals() method in C# is used to determine whether two instances of Double represent the same value. This method provides a reliable way to compare double values and handles special cases like NaN (Not a Number) values correctly. Syntax The Double.Equals() method has two overloads − public bool Equals(double obj); public override bool Equals(object obj); Parameters obj (first overload) − A Double value to compare to the current instance. obj (second overload) − An object to compare with the current instance. Return Value Returns true if the specified ...
Read More