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
Articles by AmitDiwan
Page 196 of 840
How to change the Input Encoding Scheme of the C# Console?
To change the Input Encoding Scheme of the Console in C#, use the Console.InputEncoding property. This property allows you to specify how the console interprets input characters, which is particularly useful when working with different character sets or international text. Syntax Following is the syntax for setting the console input encoding − Console.InputEncoding = Encoding.EncodingType; To retrieve the current input encoding − Encoding currentEncoding = Console.InputEncoding; Common Encoding Types Encoding Type Description Encoding.UTF8 UTF-8 encoding for Unicode characters Encoding.ASCII ASCII ...
Read MoreRandom.NextDouble() Method in C#
The Random.NextDouble() method in C# generates a random floating-point number that is greater than or equal to 0.0 and less than 1.0. This method is useful for generating decimal probabilities, percentages, or scaling random values to specific ranges. Syntax Following is the syntax for the NextDouble() method − public virtual double NextDouble(); Return Value The method returns a double value in the range [0.0, 1.0), where 0.0 is inclusive and 1.0 is exclusive. Using NextDouble() for Basic Random Numbers Example using System; public class Demo { ...
Read MoreConvert Decimal to the equivalent 64-bit unsigned integer in C#
To convert the value of a Decimal to the equivalent 64-bit unsigned integer (ulong), C# provides the Decimal.ToUInt64() method. This method truncates the decimal portion and returns only the integer part as a ulong value. Syntax Following is the syntax for converting a decimal to 64-bit unsigned integer − ulong result = Decimal.ToUInt64(decimalValue); Parameters decimalValue − A Decimal number to be converted to a 64-bit unsigned integer. Return Value Returns a ulong value equivalent to the decimal value, with the fractional part truncated (not rounded). Using Decimal.ToUInt64() with ...
Read MoreHow to change the Output Encoding Scheme of the C# Console?
The Console.OutputEncoding property in C# allows you to change the character encoding scheme used for console output. This is particularly useful when working with non-ASCII characters, special symbols, or when you need to ensure compatibility with specific encoding standards. By default, the console uses the system's default encoding, but you can override this behavior using different encoding schemes like ASCII, UTF-8, UTF-16, or Unicode. Syntax Following is the syntax for setting the output encoding − Console.OutputEncoding = Encoding.EncodingType; To get the current output encoding − Encoding currentEncoding = Console.OutputEncoding; ...
Read MoreRemoving the specified element from the List in C#
The List.Remove() method in C# removes the first occurrence of a specified element from the list. It returns true if the element was successfully removed, or false if the element was not found in the list. Syntax Following is the syntax for the Remove() method − public bool Remove(T item) Parameters item − The element to remove from the list Return Value Returns true if the element is successfully found and removed; otherwise, false. Using Remove() with String Lists The following example demonstrates removing a string element ...
Read MoreGet the TypeCode for value type Int32 in C#
The TypeCode enumeration in C# represents the type of an object. For Int32 values, the GetTypeCode() method returns TypeCode.Int32, which identifies the value as a 32-bit signed integer. The GetTypeCode() method is inherited from the Object class and implemented by value types to return their specific type identifier. Syntax Following is the syntax for getting the TypeCode of an Int32 value − TypeCode typeCode = intValue.GetTypeCode(); Return Value The GetTypeCode() method returns TypeCode.Int32 for all int variables, regardless of their actual numeric value. Using GetTypeCode() with Int32 Values Example ...
Read MoreMathF.Floor() Method in C# with Examples
The MathF.Floor() method in C# returns the largest integer that is less than or equal to a specified float value. This method performs a floor operation, effectively rounding down to the nearest integer for positive numbers and rounding away from zero for negative numbers. Syntax Following is the syntax for the MathF.Floor() method − public static float Floor(float val); Parameters val: A single-precision floating-point number for which to find the floor value. Return Value Returns a float value representing the largest integer less than or equal to the input value. If ...
Read MoreGet a value indicating whether this instance is equal to a specified object or UInt64 in C#
The UInt64.Equals() method in C# determines whether the current UInt64 instance is equal to a specified object or another UInt64 value. This method returns true if the values are equal, otherwise false. The Equals() method is inherited from the Object class and overridden in the UInt64 structure to provide value-based comparison rather than reference comparison. Syntax Following is the syntax for the UInt64.Equals() method − public bool Equals(object obj) public bool Equals(ulong value) Parameters obj − The object to compare with the current instance. value − A UInt64 ...
Read MoreSingle.IsInfinity() Method in C# with Example
The Single.IsInfinity() method in C# is used to determine whether a single-precision floating-point number represents positive or negative infinity. This method is particularly useful when performing mathematical operations that might result in infinite values, such as division by zero. Syntax Following is the syntax for the Single.IsInfinity() method − public static bool IsInfinity(float val); Parameters val − A single-precision floating-point number to be tested for infinity. Return Value The method returns true if the specified value evaluates to positive or negative infinity; otherwise, false. Single.IsInfinity() Method ...
Read MoreCheck if SortedDictionary contains the specified key or not in C#
To check if a SortedDictionary contains a specified key, C# provides the ContainsKey() method. This method returns true if the key exists in the dictionary, otherwise false. The SortedDictionary maintains its elements in sorted order by key, making key lookups efficient with O(log n) time complexity. Syntax Following is the syntax for the ContainsKey() method − public bool ContainsKey(TKey key) Parameters key − The key to locate in the SortedDictionary. Return Value Returns true if the SortedDictionary contains an element with the specified key; otherwise, false. Using ContainsKey() ...
Read More