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 by George John
Page 9 of 79
What is run time polymorphism in C#?
Runtime polymorphism in C# allows the same method call to behave differently depending on the actual type of object at runtime. This is achieved through method overriding, also known as dynamic binding or late binding. It is implemented using abstract classes and virtual functions. In runtime polymorphism, the method to be called is determined at runtime based on the object's actual type, not the reference type declared at compile time. Runtime Polymorphism Flow Base Class Circle Rectangle ...
Read MoreSize of a Three-dimensional array in C#
To get the size of a three-dimensional array in C#, you can use the GetLength() method to retrieve the size of individual dimensions, or the Length property to get the total number of elements across all dimensions. Syntax Following is the syntax for getting the size of specific dimensions − array.GetLength(dimensionIndex) Following is the syntax for getting the total number of elements − array.Length Parameters dimensionIndex − A zero-based integer representing the dimension index (0 for first dimension, 1 for second dimension, 2 for third dimension). ...
Read MoreLogical Operators on String in C#
Logical operators in C# are used to perform logical operations on boolean expressions. When working with strings, these operators are commonly used to evaluate string conditions and create compound boolean expressions for string validation and comparison logic. Logical Operators Operator Description Example && Called Logical AND operator. Returns true if both operands are true. (str != null && str.Length > 0) || Called Logical OR operator. Returns true if at least one operand is true. (str == "" || str == null) ! Called Logical NOT operator. ...
Read MoreEnumerateFiles method in C#
The Directory.EnumerateFiles() method in C# is used to enumerate all files in a specified directory. It returns an IEnumerable collection of file paths, making it memory-efficient for large directories as it processes files lazily (one at a time) rather than loading all file paths into memory at once. Syntax Following is the basic syntax for the Directory.EnumerateFiles() method − Directory.EnumerateFiles(path) Directory.EnumerateFiles(path, searchPattern) Directory.EnumerateFiles(path, searchPattern, searchOption) Parameters path − The directory path to search for files. searchPattern − The search string to match file names (e.g., "*.*" for all files, "*.txt" for text ...
Read MoreHow to List all Substrings in a given String using C#?
A substring is any contiguous sequence of characters within a string. In C#, you can generate all possible substrings of a given string using the Substring() method with nested loops to iterate through different starting positions and lengths. Syntax The Substring() method extracts a portion of a string − string.Substring(startIndex, length) To generate all substrings, use nested loops − for (int length = 1; length
Read MoreC# Enum Equals Method
The Equals() method in C# is used to compare enum values for equality. It returns true if both enum values have the same underlying value, and false otherwise. Syntax Following is the syntax for using the Equals() method with enums − enumValue1.Equals(enumValue2) Parameters enumValue2 − The enum value to compare with the current enum value Return Value The method returns a bool value − true if both enum values are equal false if the enum values are different ...
Read MoreFile Objects in C#
The FileStream class in C# is used to create, read, write, and manipulate files. It provides low-level access to file operations and is part of the System.IO namespace. FileStream works with bytes, making it suitable for both text and binary files. Syntax Following is the syntax for creating a FileStream object − FileStream objectName = new FileStream(fileName, FileMode, FileAccess, FileShare); A simplified syntax for common scenarios − FileStream objectName = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); Parameters Parameter Description Common Values fileName Path and ...
Read MoreHow to call Math Operations using Delegates in C#?
To understand how to call Math Operations using Delegates in C#, let us see an example wherein we will perform mathematical operations like division, multiplication, and addition using delegates. A delegate in C# is a type that represents references to methods with a specific signature. Syntax Following is the syntax for declaring a delegate that can reference mathematical methods − delegate returnType DelegateName(parameters); Following is the syntax for assigning methods to a delegate − DelegateName delegateInstance = MethodName; // or DelegateName delegateInstance = new DelegateName(MethodName); Using Delegates for Basic Math ...
Read MoreHow to calculate power of three using C#?
Calculating the power of a number in C# can be done using recursion, iteration, or built-in methods. This article demonstrates how to calculate powers with a focus on raising numbers to the power of 3, though the methods work for any exponent. Syntax Following is the syntax for a recursive power function − static long power(int baseNumber, int exponent) { if (exponent != 0) { return (baseNumber * power(baseNumber, exponent - 1)); } return 1; } ...
Read MoreHow to perform Matrix Addition using C#?
Matrix addition in C# involves adding corresponding elements from two matrices of the same dimensions. The matrices must have identical rows and columns for addition to be possible. The result is a new matrix where each element is the sum of the corresponding elements from the input matrices. Syntax Following is the basic syntax for matrix addition − int[, ] result = new int[rows, columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { ...
Read More