Found 2724 Articles for Csharp

C# Program to Reverse the List of Cities using LINQ

Sabid Ansari
Updated on 04-May-2023 13:49:10
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 is 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#. Before we dive into the code, let us first understand what LINQ is. 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. ... Read More

C# Program to Reverse a String without using Reverse() Method

Sabid Ansari
Updated on 04-May-2023 13:47:44
In programming, there are many situations where we need to reverse a string. One of the most common ways to do this is by using the Reverse() method. However, there are situations where we cannot use this method, and we have to reverse the string using other techniques. In this article, we will explore how to reverse a string in C# without using the Reverse() method. Before we dive into the code, let us first understand what a string is. A string is a sequence of characters that represents text. In C#, a string is a sequence of Unicode characters. ... Read More

C# Program to Read a String and Find the Sum of all Digits

Sabid Ansari
Updated on 04-May-2023 13:46:22
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. Step 1: Reading the Input String The first step in this program is to read the input string from the user. We can use the Console.ReadLine() method to read the string from the console. Here is an example − Console.WriteLine("Enter a string:"); string inputString = Console.ReadLine(); Step 2: Finding the Sum of Digits The next step ... Read More

C# Program to Read and Write a Byte Array to File using FileStream Class

Sabid Ansari
Updated on 04-May-2023 14:56:20
C# is a powerful object-oriented programming language used for developing a wide range of applications. In this article, we will discuss how to write a C# program to read and write a byte array to a file using the FileStream class. Step 1: Creating a Byte Array The first step in this program is to create a byte array that we want to write to a file. Here is an example − byte[] byteArray = { 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64 }; Step 2: Writing Byte Array to File The next step is ... Read More

Is operator in C#

Jaisshree
Updated on 25-Apr-2023 17:31:22
Is operator also called as the type-compatibility operator plays an integral role in C# structures. Let’s try to understand this operator. C#’s Is operator checks if the given object is compatible with another object and gives the result as true, if it is compatible. Else returns false. Syntax expression is obj Example Expression is the object which you like to check compatibility with. The expression can include variables, literals and method calls. Obj is the type against which the expression is verified. This can comprise of built-in and user-defined types. // The operation of the type compatibility operator is ... Read More

Inverting all bit values in BitArray in C#

Jaisshree
Updated on 25-Apr-2023 17:31:58
A BitArray is a collection of Boolean values represented as a series of 1’s and 0’s. It is often used to store and manipulate binary data efficiently. In C#, the BitArray class is part of the System. Collections namespace, and it allows you to manipulate the individual bits in the array using bitwise operators. Inverting all bit Values in a BitArray To invert all bit values in a BitArray in C#, you can use the exclusive OR (XOR) operator (^) with the number 1. This operator returns a value of 1 if the bits being compared are different and 0 ... Read More

How to use Interface References in C#?

Jaisshree
Updated on 25-Apr-2023 17:26:22
C# is an object-oriented programming language that offers a unique feature known as interfaces. They enable you to declare a collection of attributes and methods that a class must implement without mentioning the specifics of how they should be implemented. 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. ... Read More

LongLength property of an Array in C#

Jaisshree
Updated on 25-Apr-2023 17:23:07
In C#, the Array class has a read-only property called LongLength. It returns a long integer value that indicates how many elements the array can accommodate. Only arrays with a rank of one or more, i.e., those that are not single-dimensional arrays, can access the LongLength property. Although the LongLength property provides a long integer value, it's crucial to remember that the maximum size of an array in C# is still constrained by the amount of memory that the system supports. If you try to build an array that is too big, an OutOfMemoryException can be raised. Syntax public long ... Read More

How to set the alignment of Check Mark in CheckBox in C#?

Jaisshree
Updated on 25-Apr-2023 17:13:02
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 there are instances when you would wish to move it to the center or right. Alignment of the Check Mark in a CheckBox TextAlign Property To set the alignment of the check mark in a CheckBox control, you need to use the TextAlign property. The TextAlign property is an enumeration that allows you to set the horizontal alignment of the text and check mark within the control.Syntax  ... Read More

C# Program to Read the Content of a File Line by Line

Ankit kumar
Updated on 21-Apr-2023 14:37:49
Introduction Here, we’ll be learning to write a C# program to Read the content of a file content line by line. There are various methods to do so. We will be discussing them one by one. File handling is done in C#. In most cases, the file is used to store data. File handling or file management in layman’s terms the various processes such as making the file, reading from it, writing to it, appending it, and so on. The reading and writing of files are the two most common operations in file handling. 1. Using File.ReadLines() method ... Read More
Advertisements