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 77 of 2547
Decimal.ToSingle() Method in C#
The Decimal.ToSingle() method in C# is used to convert the value of the specified decimal to the equivalent single-precision floating-point number (float). This method is useful when you need to convert high-precision decimal values to float for mathematical operations or when interfacing with APIs that require float parameters. Syntax Following is the syntax − public static float ToSingle(decimal val); Parameters val − The decimal number to convert to a single-precision floating-point number. Return Value Returns a single-precision floating-point number (float) that is equivalent to the specified decimal value. Using Decimal.ToSingle() ...
Read MoreHow to use C# BinaryWriter class?
The BinaryWriter class in C# is used to write binary data to a stream in a binary format. It is part of the System.IO namespace and provides methods to write primitive data types like integers, strings, doubles, and booleans directly to a stream as binary data. Unlike text-based writing, BinaryWriter stores data in its native binary representation, making it more efficient for storage and faster to read back using BinaryReader. Syntax Following is the syntax for creating a BinaryWriter instance − BinaryWriter writer = new BinaryWriter(stream); Following is the syntax for writing data ...
Read MoreC# program to find common elements in three arrays using sets
In C#, you can find common elements in three arrays efficiently using HashSet collections. A HashSet provides fast lookups and set operations, making it ideal for finding intersections between collections of data. The HashSet class offers built-in methods like IntersectWith() that can perform set operations directly, eliminating the need for complex loops and comparisons. Syntax Following is the syntax for creating a HashSet from an array − var hashSet = new HashSet(array); Following is the syntax for finding intersection using IntersectWith() − hashSet1.IntersectWith(hashSet2); hashSet1.IntersectWith(hashSet3); Finding ...
Read MoreWhat is the difference between virtual and abstract functions in C#?
In C#, both virtual and abstract methods enable polymorphism but serve different purposes. Virtual methods provide a default implementation that can be overridden, while abstract methods have no implementation and must be overridden by derived classes. Understanding the difference between these two concepts is crucial for implementing proper inheritance hierarchies and achieving runtime polymorphism in your applications. Syntax Following is the syntax for declaring a virtual method − public virtual returnType MethodName() { // default implementation } Following is the syntax for declaring an abstract method − ...
Read MoreC# Enum IsDefined Method
The Enum.IsDefined method in C# determines whether a specified value exists within a given enumeration. It returns true if the value is found, either as an integral value or its corresponding string name, and false otherwise. Syntax Following is the syntax for the Enum.IsDefined method − public static bool IsDefined(Type enumType, object value) Parameters enumType − The type of the enumeration to check against. value − The value to look for in the enumeration (can be an integer or string). Return Value Returns true if the specified value exists ...
Read MoreC# Nested Classes
A nested class is a class declared inside another enclosing class. It is a member of its enclosing class, and nested classes can access private members of their enclosing class. However, the enclosing class cannot directly access private members of the nested class without creating an instance. Syntax Following is the syntax for declaring a nested class − public class OuterClass { // outer class members public class NestedClass { // nested class members } } ...
Read MoreChar.Parse(String) Method in C#
The Char.Parse(String) method in C# is used to convert the value of the specified string to its equivalent Unicode character. This method is particularly useful when you need to extract a single character from a string representation. Syntax Following is the syntax − public static char Parse(string s); Parameters s − A string that contains a single character, or null. Return Value Returns a Unicode character that is equivalent to the sole character in s. Examples Example 1: Parsing a Letter Character The following ...
Read MoreWhat is an object pool in C#?
An object pool in C# is a software design pattern that maintains a collection of reusable objects to optimize resource usage and improve performance. Instead of constantly creating and destroying expensive objects, the pool keeps pre-initialized objects ready for use. The object pool pattern works on two fundamental operations − Rent/Get: When an object is needed, it is retrieved from the pool. Return: When the object is no longer needed, it is returned to the pool for reuse. Object Pool Pattern ...
Read MoreC# int.Parse Method
The int.Parse method in C# converts a string representation of a number to an integer. If the string cannot be converted to a valid integer, the method throws a FormatException. Syntax Following is the basic syntax for int.Parse − int result = int.Parse(stringValue); The method also has overloaded versions that accept additional parameters − int result = int.Parse(stringValue, NumberStyles.Integer); int result = int.Parse(stringValue, CultureInfo.InvariantCulture); Parameters s − A string containing a number to convert. style (optional) − A bitwise combination of enumeration values that indicates ...
Read MoreC# program to generate secure random numbers
For secure random numbers, use the RNGCryptoServiceProvider class or the newer RandomNumberGenerator class. These implement cryptographic random number generators that are suitable for security-sensitive applications like generating passwords, tokens, or encryption keys. Secure random numbers differ from regular Random class numbers because they use entropy from the operating system and are cryptographically secure, making them unpredictable even if an attacker knows some previously generated values. Syntax Following is the syntax for generating secure random bytes − using (RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider()) { byte[] randomBytes = new byte[4]; crypto.GetBytes(randomBytes); ...
Read More