Articles on Trending Technologies

Technical articles with clear explanations and examples

C# Program to check whether a directory exists or not

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 343 Views

The Directory.Exists method in C# is used to check whether a specified directory exists on the file system. This method returns a boolean value − true if the directory exists, and false if it does not. This functionality is essential for file system operations where you need to verify directory existence before performing operations like reading files, creating subdirectories, or moving content. Syntax Following is the syntax for the Directory.Exists method − public static bool Exists(string path) Parameters path − A string representing the path to the directory to check. ...

Read More

C# Enum TryParse() Method

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 11K+ Views

The Enum.TryParse() method in C# safely attempts to convert the string representation of one or more enumerated constants to an equivalent enumerated object. Unlike Enum.Parse(), it returns a boolean value indicating success or failure instead of throwing an exception for invalid values. Syntax Following are the overloads for the Enum.TryParse() method − public static bool TryParse(string value, out TEnum result) public static bool TryParse(string value, bool ignoreCase, out TEnum result) Parameters value − The string representation of the enumeration name or underlying value to convert. ignoreCase − A ...

Read More

Type.GetNestedType() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 190 Views

The Type.GetNestedType() method in C# is used to retrieve a specific nested type that is declared within the current type. This method is part of the System.Reflection namespace and provides access to nested classes, interfaces, structs, or other types defined inside a parent type. Syntax Following are the overloads for the GetNestedType() method − public Type GetNestedType(string name); public abstract Type GetNestedType(string name, System.Reflection.BindingFlags bindingAttr); Parameters name − The string containing the simple name of the nested type to get. bindingAttr − A combination of enumeration values that specify how the search ...

Read More

C# program to count the number of words in a string

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 8K+ Views

In C#, counting the number of words in a string can be accomplished using various approaches. The most common method involves iterating through each character and identifying word separators like spaces, tabs, and newlines. Using Character-by-Character Iteration This approach loops through the string and counts whitespace characters to determine word boundaries − using System; public class Demo { public static void Main() { int a = 0, myWord = 1; string str = "Hello World!"; if (str.Length == 0) { myWord = 0; } else { while (a

Read More

C# Program to display the name of the directory

Samual Sam
Samual Sam
Updated on 17-Mar-2026 193 Views

In C# programming, you can display the name of a directory using the DirectoryInfo class from the System.IO namespace. This class provides properties and methods to work with directory information, including retrieving just the directory name without the full path. Syntax Following is the syntax for creating a DirectoryInfo object and accessing the directory name − DirectoryInfo dir = new DirectoryInfo(directoryPath); string directoryName = dir.Name; Parameters directoryPath − A string representing the path to the directory Return Value The Name property returns a string containing only the name of ...

Read More

C# Program to return the difference between two sequences

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 298 Views

In C#, you can find the difference between two sequences using the Except() method from LINQ. This method returns elements from the first sequence that do not appear in the second sequence, effectively performing a set difference operation. Syntax Following is the syntax for using the Except() method − IEnumerable result = firstSequence.Except(secondSequence); Parameters firstSequence − The sequence to return elements from. secondSequence − The sequence whose elements to exclude from the returned sequence. Return Value The method returns an IEnumerable containing the elements from the first sequence that ...

Read More

Type.GetNestedTypes() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 163 Views

The Type.GetNestedTypes() method in C# is used to get the types nested within the current Type. This method is particularly useful when working with reflection to discover and work with nested classes, interfaces, or other types defined within a class. Syntax Following is the syntax for the GetNestedTypes() method − public Type[] GetNestedTypes(); public abstract Type[] GetNestedTypes(System.Reflection.BindingFlags bindingAttr); Parameters The overloaded version accepts a BindingFlags parameter that specifies which nested types to return − bindingAttr − A combination of BindingFlags values that control which nested types are returned (e.g., Public, NonPublic, ...

Read More

C# program to count occurrences of a word in string

Samual Sam
Samual Sam
Updated on 17-Mar-2026 4K+ Views

Counting occurrences of a specific word in a string is a common string manipulation task in C#. This can be achieved using various approaches like the IndexOf() method, regular expressions, or LINQ methods. Using IndexOf() Method The IndexOf() method searches for the first occurrence of a substring and returns its position. By combining it with a loop, we can count all occurrences − using System; class Program { static void Main() { string str = "Hello World! Hello Universe! Hello!"; ...

Read More

What is the best way to iterate over a Dictionary in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

A Dictionary is a collection of key-value pairs in C#. The Dictionary class is included in the System.Collections.Generic namespace and provides several efficient ways to iterate through its elements. There are multiple approaches to iterate over a Dictionary, each with its own advantages depending on whether you need keys, values, or both. Syntax Following are the common syntaxes for iterating over a Dictionary − // Using foreach with KeyValuePair foreach (KeyValuePair item in dictionary) { // Access item.Key and item.Value } // Using foreach with var foreach (var item in dictionary) ...

Read More

What is static binding in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 1K+ Views

Static binding in C# refers to the process of linking a function call to its implementation at compile time. This is also known as early binding or compile-time polymorphism. The compiler determines which method to call based on the method signature and the types of arguments passed. C# provides two main techniques to implement static binding through static polymorphism − Function Overloading − Multiple methods with the same name but different parameters Operator Overloading − Custom implementations for operators like +, -, *, etc. Static Binding Process ...

Read More
Showing 10971–10980 of 61,297 articles
Advertisements