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
Csharp Articles
Page 72 of 196
C# Program to Get the relative path from two absolute paths
In C#, finding the relative path between two absolute paths is a common task when working with file systems. We can achieve this using the Uri class and its MakeRelativeUri method. This technique is useful for creating relative links between files or navigating within applications. An absolute path contains complete location information, such as C:\Program Files\Google\Chrome\filename.exe, while a relative path specifies location relative to the current directory, like Google\Chrome\filename.exe. Syntax Following is the syntax for creating URI instances and getting the relative path − Uri baseUri = new Uri(basePath); Uri targetUri = new Uri(targetPath); Uri ...
Read MoreHow to set the alignment of Check Mark in CheckBox in C#?
In a graphical user interface, a CheckBox control in C# enables users to pick a true/false or yes/no choice. The check mark in a CheckBox control is normally aligned to the left, but you can customize its position using the CheckAlign property. Syntax The syntax to change the alignment of the check mark is − checkBox1.CheckAlign = ContentAlignment.MiddleRight; The CheckAlign property accepts values from the ContentAlignment enumeration − MiddleLeft − Align the check mark to the left edge of the control (default). MiddleRight − Align the check mark to ...
Read MoreHow to use Interface References in C#?
C# is an object-oriented programming language that offers a unique feature known as interfaces. They enable you to declare a collection of methods and properties that a class must implement without specifying the implementation details. The ability to write code that is independent of a class's implementation details is one of the main benefits of interfaces. Each object of any class that implements the interface can be referred to using an interface reference. As a result, it is simpler to switch between different class implementations without having to modify the code that utilizes the class. Syntax for ...
Read MoreIs operator in C#
The is operator in C# is a type-compatibility operator that checks if an object is compatible with a specific type. It returns true if the object is compatible with the specified type, otherwise it returns false. This operator is essential for type checking and safe casting operations in C#. Syntax Following is the basic syntax of the is operator − expression is type Where expression is the object to check, and type is the type to check against. Basic Type Checking Example using System; class Program { ...
Read MoreInverting all bit values in BitArray in C#
The BitArray class in C# is a collection of Boolean values represented as bits (1's and 0's). It is part of the System.Collections namespace and provides efficient storage and manipulation of binary data. One common operation is inverting all bit values in a BitArray. Syntax Following are the common methods to invert all bits in a BitArray − // Using built-in Not() method bitArray.Not(); // Using XOR with true bits[i] ^= true; // Using Set() method with negation bits.Set(i, !bits[i]); Using the Built-in Not() Method The simplest way to invert all ...
Read MoreC# Program to Read a String and Find the Sum of all Digits
C# is a popular object-oriented programming language used to develop Windows applications, web applications, and games. In this article, we will discuss how to write a C# program to read a string and find the sum of all digits present in the string. Approach To find the sum of digits in a string, we need to iterate through each character, check if it's a digit using char.IsDigit(), and convert it to an integer to add to our running sum. Using char.IsDigit() Method The char.IsDigit() method determines whether a character represents a decimal digit. Here's the complete ...
Read MoreC# Program to Reverse the List of Cities using LINQ
In C#, LINQ (Language Integrated Query) is a powerful feature that allows us to perform queries on various data sources, including arrays, lists, and databases. It provides an efficient and concise way to manipulate data and has become an essential tool for developers. In this article, we will explore how to use LINQ to reverse a list of cities in C#. LINQ is a set of extensions to the .NET Framework that provides a standard way to query data from different data sources using a common syntax. It allows developers to write queries that resemble SQL statements, making it ...
Read MoreC# Program to Search Sub-Directory in a Given Directory
Searching for sub-directories in a given directory is a common task in many applications. In C#, we can use the Directory and DirectoryInfo classes provided by the System.IO namespace to perform this task. In this article, we will explore how to write a C# program to search for sub-directories in a given directory. Syntax Following is the syntax for using DirectoryInfo.GetDirectories() method − DirectoryInfo directoryInfo = new DirectoryInfo(path); DirectoryInfo[] subdirectories = directoryInfo.GetDirectories(); Following is the syntax for using Directory.GetDirectories() method − string[] subdirectories = Directory.GetDirectories(path); Using DirectoryInfo.GetDirectories() The DirectoryInfo.GetDirectories() ...
Read MoreC# Program to Show the Use of Exists Property
The Exists method in C# is a useful method that checks whether any element in a List matches a given condition. This method takes a predicate as an argument and returns a bool value indicating whether any element exists in the list that satisfies the specified condition. Syntax Following is the syntax for the Exists method − public bool Exists(Predicate match) Parameters match − A Predicate delegate that defines the conditions of the elements to search for. Return Value Returns true if at least one element matches the specified ...
Read MoreC# Program to Show the Use of GetEnvironmentVariable() Method of Environment Class
The GetEnvironmentVariable() method of the Environment class in C# is used to retrieve the value of an environment variable. This method is essential for accessing system-wide and user-specific environment variables such as PATH, TEMP, or custom variables set by applications. Syntax Following is the basic syntax for the GetEnvironmentVariable() method − public static string GetEnvironmentVariable(string variable) There is also an overloaded version that accepts an EnvironmentVariableTarget parameter − public static string GetEnvironmentVariable(string variable, EnvironmentVariableTarget target) Parameters variable − A string containing the name of the environment variable. target ...
Read More