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 on Trending Technologies
Technical articles with clear explanations and examples
How to call a method of a class in C#
To call a method of a class in C#, you need to create an instance of the class first, then use the dot notation to access its methods. The general syntax is objectName.MethodName(parameters). Syntax Following is the syntax for calling an instance method − ClassName objectName = new ClassName(); returnType result = objectName.MethodName(parameters); For static methods, you call them directly on the class without creating an instance − returnType result = ClassName.StaticMethodName(parameters); Using Instance Methods Instance methods require an object of the class to be called. Here's how you ...
Read MoreWhat are static or fixed length arrays in C#?
A static array or fixed-length array in C# is a data structure with a predetermined size that cannot be changed after creation. Once you declare an array with a specific length, that size remains constant throughout the program's execution. Static arrays are different from dynamic collections like List because their size is immutable. This makes them memory-efficient and provides predictable performance characteristics. Syntax Following is the syntax for declaring a static array − dataType[] arrayName = new dataType[size]; You can also initialize a static array with values at declaration − dataType[] ...
Read MoreWhat is the difference between Write() and WriteLine() methods in C#?
The difference between Write() and WriteLine() methods in C# is based on the new line character. Both methods are used to display output to the console, but they handle line termination differently. Write() method displays the output but does not provide a new line character, so subsequent output appears on the same line. WriteLine() method displays the output and automatically adds a new line character at the end, moving the cursor to the next line for subsequent output. Syntax Following is the syntax for Write() method − Console.Write(value); Console.Write("text"); Following is the syntax ...
Read MoreC# Linq ThenBy Method
The ThenBy() method in C# LINQ is used to perform a secondary sort on a sequence that has already been ordered using OrderBy(). It allows you to sort by multiple criteria, where OrderBy() defines the primary sort and ThenBy() defines the secondary sort for elements that are equal in the primary sort. Syntax Following is the syntax for using ThenBy() method − IEnumerable result = source.OrderBy(keySelector1).ThenBy(keySelector2); You can chain multiple ThenBy() methods for additional sort levels − IEnumerable result = source.OrderBy(key1).ThenBy(key2).ThenBy(key3); Parameters keySelector − A function that ...
Read MoreConvert.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 More