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 810 of 2547
Overriding 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 MoreHow to reverse a String using C#?
In C# there are multiple ways to reverse a string. The most common approach is using the Array.Reverse() method, but you can also use other techniques like loops or LINQ methods for different scenarios. Using Array.Reverse() Method The Array.Reverse() method is the most efficient way to reverse a string. First, convert the string to a character array, then apply the reverse method − using System; class Program { static void Main(string[] args) { string str = "Amit"; ...
Read MoreC# program to display the previous day
To display the previous day in C#, use the AddDays() method with a value of -1. This method allows you to add or subtract days from a DateTime object. Syntax Following is the syntax for getting the current date − DateTime.Today Following is the syntax for getting the previous day using AddDays() − DateTime.Today.AddDays(-1) Using DateTime.Today.AddDays(-1) The DateTime.Today property returns the current date with the time set to midnight. The AddDays(-1) method subtracts one day from this date − using System; public class Demo { ...
Read More