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
Are arrays zero indexed in C#?
Yes, arrays are zero-indexed in C#. This means the first element of an array is stored at index 0, the second element at index 1, and so on. The relationship between array length and indexing follows a consistent pattern. Array Length vs Index Range If the array is empty, it has zero elements and length 0. If the array has one element at index 0, then it has length 1. If the array has two elements at indexes 0 and 1, then it has length 2. If the array has ...
Read MoreWay to read input from console in C#
The Console.ReadLine() method is the primary way to read input from the console in C#. This method reads a complete line of text from the console and returns it as a string. Since all console input is received as text, you need to convert it to the appropriate data type when working with numbers or other non-string values. Syntax Following is the syntax for reading console input − string input = Console.ReadLine(); For converting string input to other data types − int number = Convert.ToInt32(input); ...
Read MoreOverriding in C#
Method overriding in C# enables runtime polymorphism by allowing a derived class to provide a specific implementation of a method that is already defined in its base class. This is achieved using the virtual keyword in the base class and the override keyword in the derived class. Overriding is essential for implementing dynamic polymorphism, where the method to be called is determined at runtime based on the actual object type rather than the reference type. Syntax Following is the syntax for method overriding using virtual and override keywords − // Base class with virtual method ...
Read MoreHow to negate the positive elements of an integer array in C#?
Negating the positive elements of an integer array means converting all positive values to their negative counterparts while leaving negative and zero values unchanged. This operation is useful in various mathematical computations and data processing scenarios. Syntax Following is the basic syntax to check and negate positive elements − if (arr[i] > 0) arr[i] = -arr[i]; A complete loop structure to process all array elements − for (int i = 0; i < arr.Length; i++) { if (arr[i] > 0) ...
Read MoreMath.Cosh() Method in C#
The Math.Cosh() method in C# returns the hyperbolic cosine of a specified angle in radians. The hyperbolic cosine function is defined mathematically as cosh(x) = (e^x + e^(-x)) / 2, where e is Euler's number. This method is commonly used in mathematical calculations involving hyperbolic functions, engineering applications, and statistical computations. Syntax Following is the syntax − public static double Cosh(double value); Parameters value − A double representing an angle measured in radians. Return Value Returns a double representing the hyperbolic cosine of the specified value. If the ...
Read MoreChar.IsPunctuation() Method in C#
The Char.IsPunctuation() method in C# determines whether a specified Unicode character is categorized as a punctuation mark. This method is useful for text processing, input validation, and character analysis tasks. Syntax Following is the syntax − public static bool IsPunctuation(char ch); Parameters ch − The Unicode character to evaluate. Return Value Returns true if the character is a punctuation mark; otherwise, false. Character Classification Punctuation ! ? . , ; : " ' ...
Read MorePrivate Methods in C#
Private methods in C# can only be accessed within the class where they are defined. They use the private access modifier to restrict visibility and are commonly used for internal helper functionality that should not be exposed to external code. The private access specifier allows a class to hide its member variables and member functions from other functions and objects. Only methods within the same class can access private members, providing encapsulation and data hiding. Syntax Following is the syntax for declaring a private method − private returnType MethodName(parameters) { // method ...
Read MoreHow to convert an array of characters into a string in C#?
Converting an array of characters into a string is a common operation in C#. There are multiple approaches to accomplish this, each suitable for different scenarios. Syntax Following is the syntax for converting a character array to string using the string constructor − string str = new string(charArray); Following is the syntax using the string constructor with range specification − string str = new string(charArray, startIndex, length); Using String Constructor The simplest way to convert a character array to a string is using the string constructor that accepts a ...
Read MoreC# program to Loop over a two dimensional array
A two-dimensional array in C# stores elements in a grid format with rows and columns. To loop through all elements, you need to iterate through both dimensions using nested loops. Syntax Following is the syntax for declaring a two-dimensional array − dataType[,] arrayName = new dataType[rows, columns]; Following is the syntax for looping through a two-dimensional array using nested for loops − for (int i = 0; i
Read MoreMath.Log() Method in C#
The Math.Log() method in C# is used to return the logarithm of a specified number. This method provides two overloads: one for calculating the natural logarithm (base e) and another for calculating logarithm with a specified base. Syntax Following are the two overloads of the Math.Log() method − public static double Log(double num) public static double Log(double num, double newBase) Parameters num − The number whose logarithm is to be calculated (must be positive for real results). newBase − The base of the logarithm (must be positive and not equal to 1). ...
Read More