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 836 of 2547
Convert.ToBase64CharArray() Method in C#
The Convert.ToBase64CharArray() method in C# converts a subset of an 8-bit unsigned integer array to an equivalent subset of a Unicode character array encoded with base-64 digits. This method provides more control than the standard Convert.ToBase64String() by allowing you to specify input and output positions and work directly with character arrays. Syntax Following is the syntax − public static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut); Parameters inArray − An input array of 8-bit unsigned integers (bytes). offsetIn − A position within the input array to start conversion. ...
Read MoreBoolean.ToString() Method in C#
The Boolean.ToString() method in C# converts a boolean value to its equivalent string representation. It returns "True" for true values and "False" for false values. Syntax Following is the syntax − public override string ToString(); Return Value The method returns a string that represents the current boolean value − Returns "True" if the boolean value is true Returns "False" if the boolean value is false Using Boolean.ToString() with True Value Example using System; public class Demo { ...
Read MoreSkipWhile method in C#
The SkipWhile method in C# is a LINQ extension method that skips elements from the beginning of a sequence as long as a specified condition is true. It stops skipping once it encounters the first element that doesn't meet the condition and returns all remaining elements, including any subsequent elements that might match the condition again. This method is particularly useful when you need to skip a consecutive sequence of elements from the start of a collection based on a specific criteria. Syntax Following is the syntax for the SkipWhile method − public static IEnumerable ...
Read MoreType.GetProperties() Method in C#
The Type.GetProperties() method in C# is used to retrieve information about the properties of a specific type at runtime using reflection. This method returns an array of PropertyInfo objects that represent all the properties of the specified type. Syntax Following are the two main overloads of the GetProperties() method − public PropertyInfo[] GetProperties(); public PropertyInfo[] GetProperties(BindingFlags bindingAttr); Parameters bindingAttr − A bitwise combination of BindingFlags enumeration values that specify how the search is conducted. This parameter controls which properties are returned based on their accessibility and binding characteristics. Return Value ...
Read MoreHow to capture divide by zero exception in C#?
The System.DivideByZeroException is a class that handles errors generated from dividing a number by zero. This exception occurs when you attempt to divide an integer or decimal value by zero during arithmetic operations. In C#, you can capture and handle this exception using try-catch blocks to prevent your application from crashing and provide meaningful error messages to users. Syntax Following is the syntax for handling divide by zero exception − try { result = dividend / divisor; } catch (DivideByZeroException e) { // Handle the exception ...
Read MoreRandom Numbers in C#
The Random class in C# is used to generate pseudo-random numbers. It provides various methods to generate random integers, doubles, and bytes within specified ranges. Syntax Following is the syntax for creating a Random object and generating random numbers − Random rd = new Random(); int randomNumber = rd.Next(minValue, maxValue); Following are the commonly used methods of the Random class − rd.Next() // Random int from 0 to int.MaxValue rd.Next(maxValue) ...
Read MoreC# Queryable Union Method
The Queryable Union method in C# performs a set union operation on two sequences, returning all unique elements from both sequences. It removes duplicate elements and preserves the order of first occurrence. Syntax Following is the syntax for the Queryable Union method − public static IQueryable Union( this IQueryable source1, IEnumerable source2 ) Parameters source1 − An IQueryable whose distinct elements form the first set for the union. source2 − An IEnumerable whose distinct elements form the second set for the union. ...
Read MoreType.GetTypeArray() Method in C#
The Type.GetTypeArray() method in C# is used to retrieve the Type objects representing the runtime types of all elements in a specified object array. This method is particularly useful in reflection scenarios where you need to determine the actual types of objects at runtime. Syntax Following is the syntax − public static Type[] GetTypeArray (object[] args); Parameters args − An array of objects whose types are to be determined. Return Value This method returns an array of Type objects representing the types of the corresponding elements in ...
Read MoreRemove Leading Zeros from a String in C#
Removing leading zeros from a string is a common requirement in C# when dealing with numeric data or formatted strings. There are several approaches to accomplish this task, with TrimStart() being the most straightforward method. Syntax Following is the syntax for using TrimStart() to remove leading zeros − string.TrimStart('0') string.TrimStart(new char[] { '0' }) Using TrimStart() Method The TrimStart() method removes specified characters from the beginning of a string. To remove leading zeros, we pass '0' as the character to trim − using System; class Program { ...
Read MoreC# Program to get the first three elements from a list
The Take() method in C# is a LINQ extension method used to retrieve a specified number of elements from the beginning of a collection. It returns an IEnumerable containing the first n elements from the original collection. Syntax Following is the syntax for using the Take() method − IEnumerable Take(int count) Parameters count − An integer specifying the number of elements to return from the start of the sequence. Return Value The Take() method returns an IEnumerable that contains the specified number of elements from the start ...
Read More