George John

George John

789 Articles Published

Articles by George John

Page 10 of 79

How to open hidden file using C#?

George John
George John
Updated on 17-Mar-2026 769 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 932 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 622 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 311 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

Intersect two lists in C#

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

In C#, you can find common elements between two lists using the Intersect() method from LINQ. This method returns an IEnumerable containing elements that appear in both lists, automatically removing duplicates. Syntax Following is the syntax for using the Intersect() method − IEnumerable result = list1.Intersect(list2); The method can also accept a custom equality comparer − IEnumerable result = list1.Intersect(list2, comparer); Using Intersect() with Integer Lists The most common use case is finding intersection between two integer lists − using System; using System.Collections.Generic; using System.Linq; class ...

Read More

Enum with Customized Value in C#

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

An enum (enumeration) in C# is used to store a set of named constants such as days of the week, months, seasons, or any fixed collection of related values. By default, enum constants start from 0 and increment by 1, but you can customize these values to match your specific requirements. Customizing enum values is useful when you need specific numeric representations, want to maintain compatibility with external systems, or need non-sequential numbering. Syntax Following is the syntax for declaring an enum with customized values − public enum EnumName { Value1 ...

Read More
Showing 91–100 of 789 articles
« Prev 1 8 9 10 11 12 79 Next »
Advertisements