George John

George John

789 Articles Published

Articles by George John

Page 11 of 79

How to calculate power of three using C#?

George John
George John
Updated on 17-Mar-2026 406 Views

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 More

How to perform Matrix Addition using C#?

George John
George John
Updated on 17-Mar-2026 1K+ Views

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

How to open hidden file using C#?

George John
George John
Updated on 17-Mar-2026 781 Views

To open a hidden file in C#, you need to first make it visible by removing the hidden attribute, then read its contents, and optionally restore the hidden attribute afterward. Hidden files have the FileAttributes.Hidden attribute set, which prevents them from being displayed in normal file explorers. Syntax Following is the syntax for removing the hidden attribute from a file − FileInfo file = new FileInfo(filePath); file.Attributes &= ~FileAttributes.Hidden; Following is the syntax for restoring the hidden attribute − file.Attributes |= FileAttributes.Hidden; Using FileInfo to Remove Hidden Attribute The ...

Read More

What is the C# equivalent to Java's isInstance()?

George John
George John
Updated on 17-Mar-2026 947 Views

Java's isInstance() method determines if a specified object is assignment-compatible with the object represented by a class. In C#, there are several equivalent approaches to achieve the same functionality for type checking and instance validation. C# Equivalents to Java's isInstance() The most common C# equivalents are the is operator, IsAssignableFrom() method, and IsInstanceOfType() method. Each serves different use cases depending on whether you're working with objects, types, or need runtime type checking. Using the 'is' Operator The simplest and most commonly used equivalent is the is operator − bool result = (object is ClassName); ...

Read More

How to check if a C# list is empty?

George John
George John
Updated on 17-Mar-2026 3K+ Views

In C#, there are several ways to check if a List is empty. The most common approaches include using the Count property, the Any() LINQ method, or comparing against an empty collection. Syntax Following are the common syntaxes for checking if a list is empty − // Using Count property if (list.Count == 0) { } // Using Any() method if (!list.Any()) { } // Using Count with comparison if (list.Count > 0) { } Using Count Property The Count property returns the number of elements in the list. When Count ...

Read More

static keyword in C#

George John
George John
Updated on 17-Mar-2026 3K+ Views

The static keyword in C# is used to declare class members that belong to the class itself rather than to any specific instance. When a member is declared as static, it means there is only one copy of that member shared across all instances of the class. Static members can be accessed directly using the class name without creating an object instance. They are commonly used for utility methods, constants, and shared data that should be consistent across all instances of a class. Syntax Following is the syntax for declaring static members − public static ...

Read More

How to compare two Dates in C#?

George John
George John
Updated on 17-Mar-2026 1K+ Views

To compare dates in C#, you need to first set two dates to be compared using the DateTime object. The DateTime class in C# provides several methods and operators for date comparison including direct comparison operators, the CompareTo() method, and specialized methods like Equals(). Syntax Following are the different syntaxes for comparing dates − // Using comparison operators if (date1 < date2) { } if (date1 > date2) { } if (date1 == date2) { } // Using CompareTo method int result = date1.CompareTo(date2); // Using Equals method bool isEqual = date1.Equals(date2); ...

Read More

How to print duplicate characters in a String using C#?

George John
George John
Updated on 17-Mar-2026 5K+ Views

Finding duplicate characters in a string is a common programming task in C#. A duplicate character is one that appears more than once in the string. We can solve this by counting the frequency of each character and then displaying those with a count greater than 1. Using Character Frequency Array The most efficient approach uses an integer array to store the frequency of each character. Since there are 256 possible ASCII characters, we create an array of size 256 − using System; class Demo { static int maxCHARS = 256; ...

Read More

Different Methods to find Prime Numbers in C#

George John
George John
Updated on 17-Mar-2026 639 Views

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In C#, there are several methods to check if a number is prime, each with different approaches and efficiency levels. What is a Prime Number? A prime number is divisible only by 1 and itself. For example, 2, 3, 5, 7, 11 are prime numbers. The number 1 is not considered prime, and 2 is the only even prime number. Prime vs Composite Numbers Prime Numbers ...

Read More

Why is a Dictionary preferred over a Hashtable in C#?

George John
George John
Updated on 17-Mar-2026 328 Views

In C#, Dictionary is generally preferred over Hashtable due to its better performance, type safety, and modern design. Both are key-value collections, but Dictionary provides significant advantages for most applications. A Hashtable is a non-generic collection that stores key-value pairs as object types, requiring boxing and unboxing operations. A Dictionary is a generic collection from the System.Collections.Generic namespace that provides compile-time type safety and better performance. Key Differences Feature Hashtable Dictionary Type Safety No compile-time type checking Strong type checking at compile-time Performance Slower due to boxing/unboxing Faster, ...

Read More
Showing 101–110 of 789 articles
« Prev 1 9 10 11 12 13 79 Next »
Advertisements