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
Server Side Programming Articles
Page 749 of 2109
How 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 MoreC# Program to Sort a List of String Names Using the LINQ OrderBy() Method
Sorting a list of string names is a common task in programming, and the LINQ OrderBy() method in C# provides an elegant and efficient way to accomplish this. In this article, we will explore how to sort string lists using LINQ, including both ascending and descending order sorting. What is LINQ OrderBy() Method? The LINQ OrderBy() method is used to sort elements of a sequence in ascending order based on a specified key. For descending order, you use OrderByDescending(). These methods work with any IEnumerable collection and return an IOrderedEnumerable. Syntax Following is the syntax for ...
Read MoreC# Program to Append Text to an Existing File
Appending text means adding new information to the end of an existing file. In C#, we can append text to files using various methods from the System.IO namespace. This is particularly useful for logging, data collection, and maintaining records. Behavior with Non-Existing Files When attempting to append to a file that doesn't exist, C# automatically creates a new file with the specified name and then adds the content. This eliminates the need for separate file existence checks in most scenarios. Using File.AppendAllText() Method Syntax public static void AppendAllText(string path, string contents); This ...
Read More