Ankit kumar

Ankit kumar

16 Articles Published

Articles by Ankit kumar

Page 2 of 2

C# Program to Find the List of Students whose Name Starts with ‘S’ using where() Method of List Collection using LINQ

Ankit kumar
Ankit kumar
Updated on 17-Mar-2026 580 Views

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 More

C# Program to Get the relative path from two absolute paths

Ankit kumar
Ankit kumar
Updated on 17-Mar-2026 6K+ Views

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 More

C# Program to Find the Negative Double Numbers From the List of Objects Using LINQ

Ankit kumar
Ankit kumar
Updated on 17-Mar-2026 582 Views

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 More

C# Program to Generate Odd Numbers in Parallel using LINQ

Ankit kumar
Ankit kumar
Updated on 17-Mar-2026 564 Views

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 More

C# Program to Generate Random Even Numbers Using LINQ Parallel Query

Ankit kumar
Ankit kumar
Updated on 17-Mar-2026 1K+ Views

In this article, we will learn how to write a C# program that uses LINQ parallel query to generate random even numbers. LINQ (Language Integrated Query) is a powerful feature of C# that allows developers to query data from various sources using a consistent syntax. Parallel LINQ (PLINQ) extends LINQ to execute queries in parallel, improving performance for large datasets. Problem Explanation We need to create a program that generates random even numbers using LINQ parallel query. The solution involves using ParallelEnumerable.Range() to create a sequence of numbers, then applying the Where() clause to filter even numbers and ...

Read More

C# Program to Append Text to an Existing File

Ankit kumar
Ankit kumar
Updated on 17-Mar-2026 11K+ Views

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
Showing 11–16 of 16 articles
« Prev 1 2 Next »
Advertisements