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 47 of 2547
How 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 MoreHow to Convert Hashtable into an Array?
The Hashtable collection in C# is a non-generic collection of key-value pairs where each key is unique and non-null, while values can be duplicated or null. Converting a Hashtable into an array is a common operation when you need to work with the data in array format. The Hashtable class provides the CopyTo method to efficiently transfer its elements to an array. This method copies Hashtable items as DictionaryEntry objects to a one-dimensional array. Syntax Following is the syntax for the CopyTo method − public virtual void CopyTo(Array array, int arrayIndex); Parameters ...
Read MoreHow to prove that only one instance of the object is created for static class?
In C#, a static class ensures that only one instance exists throughout the application's lifetime. To prove this concept, we can demonstrate how static variables maintain their state across multiple accesses, and how the static constructor is called only once. A static class cannot be instantiated using the new keyword. Instead, all members belong to the type itself rather than to any specific instance. This behavior proves that only one "instance" of the static class exists in memory. Syntax Following is the syntax for declaring a static class with static members − static class ClassName ...
Read MoreHow to resize an Image C#?
Image resizing in C# is a common requirement for optimizing storage space, improving loading times, and adjusting images for different display contexts. The System.Drawing namespace provides the Bitmap class and related classes to handle image manipulation tasks including resizing, compression, and format conversion. A bitmap consists of pixel data for a graphics image and its attributes. GDI+ supports multiple file formats including BMP, GIF, EXIF, JPG, PNG, and TIFF. You can create images from files, streams, and other sources using Bitmap constructors and save them using the Save method. Basic Image Resizing The most straightforward approach to ...
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 MoreWhat is the difference between Select and SelectMany in Linq C#?
The Select and SelectMany operators in LINQ C# serve different purposes for data projection. Select produces one result value for every source element, while SelectMany belongs to Projection Operators category and is used to project each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence. Syntax Following is the syntax for Select operator − IEnumerable Select( this IEnumerable source, Func selector ) Following is the syntax for SelectMany operator − IEnumerable SelectMany( this IEnumerable source, ...
Read MoreHow to get a path to the desktop for current user in C#?
The desktop path of the current user can be fetched using Environment.GetFolderPath() with the Environment.SpecialFolder.Desktop enumeration. This method provides a reliable, cross-platform way to access special system folders. Syntax Following is the syntax for getting the desktop path − string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); The Environment.GetFolderPath() method takes an Environment.SpecialFolder enumeration value and returns the path to that special folder as a string. Parameters The method accepts the following parameter − folder − An Environment.SpecialFolder enumeration value that identifies the special folder whose path is to be retrieved. Return ...
Read More