Ankit kumar

Ankit kumar

16 Articles Published

Articles by Ankit kumar

16 articles

C# Program to check if a path is a directory or a file

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

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 More

C# Program to Copy a File

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

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 More

C# Program to Delete Empty and Nonempty Directory

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

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 More

C# Program to Create File and Write to the File

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

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 More

C# Program to Find Integer Numbers from the List of Objects and Sort them Using LINQ

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

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 More

C# Program to Find out the value of Sin(x)

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

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 More

C# Program to find the greatest number in an array using the WHERE clause LINQ

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

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

C# Program to Generate Marksheet of Student

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

A marksheet generation program is a practical application that calculates a student's total marks, percentage, and grade based on subject scores. This C# program demonstrates how to create a simple marksheet system using basic input/output operations, arithmetic calculations, and conditional logic. Algorithm The marksheet generation follows these steps − Step 1 − Declare variables for student roll number, name, subject marks, total marks, and percentage. Step 2 − Accept input for student details and marks in each subject. Step 3 − Calculate total marks by summing all subject marks. Step 4 − Calculate percentage ...

Read More

C# Program to estimate the size of the file using LINQ

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

The Language Integrated Query (LINQ) in C# provides powerful methods to work with data from various sources, including files and directories. In this article, we'll explore how to estimate file sizes using LINQ operations, specifically calculating the average file size in a directory. LINQ is part of the .NET framework that enables developers to write queries directly in C# using a SQL-like syntax. It provides a unified approach to query data from different sources like collections, databases, XML documents, and file systems. Syntax Following is the basic syntax for using LINQ to work with file information − ...

Read More

C# Program to Get and Print the Command Line Arguments Using Environment Class

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

The Environment class in C# provides access to current environment and platform information, including command line arguments. The Environment.CommandLine property retrieves the complete command line that started the current process, including the executable name and all arguments. Environment Class Overview The Environment class offers various properties and methods to access system information − Environment.CommandLine − Gets the complete command line Environment.GetCommandLineArgs() − Gets arguments as a string array Environment.CurrentDirectory − Gets current working directory Environment.OSVersion − Gets operating system version Environment.MachineName − Gets computer name Environment.ProcessorCount − Gets processor count ...

Read More
Showing 1–10 of 16 articles
« Prev 1 2 Next »
Advertisements