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 71 of 196
C# Program to Find the List of Students whose Name Starts with ‘S’ using where() Method of List Collection using LINQ
The Where() method in LINQ is a powerful filtering tool that allows you to query collections based on specific conditions. This article demonstrates how to use the Where() method with a List collection to find students whose names start with the letter 'S'. LINQ (Language Integrated Query) is a .NET framework feature that provides a consistent way to query different data sources using C# syntax. It eliminates the need for separate query languages like SQL when working with in-memory collections, making data filtering and manipulation more intuitive. Syntax The Where() method has the following syntax − ...
Read MoreC# Program to Find the Negative Double Numbers From the List of Objects Using LINQ
In this article, we will learn how to write a C# program to find the negative double numbers from a list of objects using LINQ. LINQ (Language Integrated Query) is a powerful feature in C# that allows developers to query data from various sources including arrays, collections, and databases. It provides SQL-like syntax for data manipulation and filtering, making complex data operations simple and readable. Problem Statement Given a list of objects containing different data types, we need to find only the negative double numbers using LINQ. This requires two filtering steps − Filter elements ...
Read MoreC# Program to Generate Odd Numbers in Parallel using LINQ
This article demonstrates how to generate odd numbers in parallel using LINQ in C#. LINQ (Language Integrated Query) provides a powerful way to query data from collections, arrays, and databases using a SQL-like syntax. When combined with parallel processing, LINQ can efficiently handle large datasets by distributing work across multiple CPU cores. Syntax Following is the syntax for generating odd numbers in parallel using LINQ − IEnumerable odds = ParallelEnumerable.Range(start, count) .Where(x => x % 2 != 0) .Select(x => x); LINQ Methods Used Where() ...
Read MoreC# Program to Create File and Write to the File
Creating files and writing data to them is a fundamental aspect of file handling in C#. The System.IO namespace provides several methods to create and write to files efficiently. This article covers various approaches to create files and write content using different methods. File handling operations rely on streams, which provide a generic view of a sequence of bytes. Streams serve as the gateway between your application and file operations, enabling input and output processes. Using File.WriteAllText() Method The File.WriteAllText() method is one of the simplest ways to create a file and write text content. It creates ...
Read MoreC# Program to check if a path is a directory or a file
In C# programming, determining whether a given path points to a directory or a file is a common task. A directory (also called a folder) is a container that organizes files and other directories on your computer. A file is a collection of data stored with a unique name and path. The .NET framework provides built-in methods in the System.IO namespace to check path types efficiently using File.Exists() and Directory.Exists() methods. Syntax Following is the syntax for checking file existence − public static bool File.Exists(string path); Following is the syntax for checking directory ...
Read MoreC# Program to Copy a File
C# provides built-in functionality for file operations through the System.IO namespace. File copying is a fundamental operation that allows you to duplicate existing files to new locations or with different names. The File.Copy() method offers a straightforward way to copy files with optional overwrite capabilities. Syntax The File.Copy() method has two overloads − public static void Copy(string sourceFileName, string destFileName); public static void Copy(string sourceFileName, string destFileName, bool overwrite); Parameters sourceFileName − The path and name of the file to copy. destFileName − The path and name of the ...
Read MoreC# Program to Delete Empty and Nonempty Directory
In C#, directories (folders) are used to organize files and other directories on the computer. The Directory class provides static methods for managing directories, while DirectoryInfo provides instance methods for working with specific directories. This article demonstrates how to delete both empty and non-empty directories using C#. Syntax The Directory.Delete() method has two overloads for deleting directories − public static void Delete(string path); public static void Delete(string path, bool recursive); Parameters path − The directory path to delete (string type) recursive − true to delete subdirectories and files; false ...
Read MoreC# Program to Find Integer Numbers from the List of Objects and Sort them Using LINQ
In this article, we will learn how to write a C# program to find integer numbers from a list of objects and sort them using LINQ. LINQ (Language Integrated Query) is one of C#'s powerful features that enables developers to query data from various sources using a SQL-like syntax. It provides a standard approach for data manipulation and sorting, regardless of the data source. Problem Statement We need to extract integer numbers from a heterogeneous list containing different data types (strings, integers, characters) and sort them in ascending order. We'll use LINQ's OfType() method to filter integers and ...
Read MoreC# Program to Find out the value of Sin(x)
In this article, we will learn how to create a C# program to find the value of Sin(x). The sine function is a fundamental trigonometric function that calculates the ratio of the opposite side to the hypotenuse in a right triangle. C# provides built-in methods to calculate sine values, and we can also implement our own calculation using mathematical series. Syntax C# provides a built-in method in the Math class to calculate sine values − Math.Sin(double angleInRadians) The Maclaurin series expansion for sin(x) is − sin(x) = x - x³/3! + x⁵/5! ...
Read MoreC# Program to find the greatest number in an array using the WHERE clause LINQ
In this article, we will find the greatest number in an array using the WHERE clause in LINQ. LINQ (Language Integrated Query) provides a unified way to query data from different sources in C#, making code more readable and concise with built-in filtering, sorting, and grouping capabilities. Language Integrated Query (LINQ) LINQ is a component of the .NET framework that allows type-safe data access from various sources like databases, XML documents, and collections. It uses clauses to perform different operations on data − From Clause − Specifies the data source and range variable. Where Clause − ...
Read More