Programming Articles

Page 701 of 2547

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

Ankit kumar
Ankit kumar
Updated on 17-Mar-2026 321 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

Check if ListDictionary is read-only in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 193 Views

The ListDictionary class in C# provides an IsReadOnly property to check if the dictionary is read-only. This property returns false for a standard ListDictionary, as it allows adding, removing, and modifying elements. However, you can create read-only wrappers using collection utilities. Syntax Following is the syntax to check if a ListDictionary is read-only − bool isReadOnly = listDictionary.IsReadOnly; Using IsReadOnly Property Example using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ ListDictionary dict1 ...

Read More

How to check whether a List contains a specified element in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 672 Views

To check whether a List contains a specified element in C#, you use the Contains() method. This method returns true if the element is found in the list, and false otherwise. Syntax Following is the syntax for the Contains() method − bool Contains(T item) Parameters item: The element to search for in the list. The type T represents the element type of the list. Return Value Returns a bool value − true if the item is found, false if not found. List.Contains() Method ...

Read More

Check if ListDictionary is synchronized in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 155 Views

The ListDictionary class in C# provides the IsSynchronized property to check if the collection is synchronized (thread-safe). By default, ListDictionary is not synchronized, meaning it is not thread-safe for concurrent access by multiple threads. Syntax Following is the syntax to check if a ListDictionary is synchronized − bool isSynchronized = listDictionary.IsSynchronized; Return Value The IsSynchronized property returns a bool value − true − if the ListDictionary is synchronized (thread-safe) false − if the ListDictionary is not synchronized (not thread-safe) Example The following example demonstrates how to check if ...

Read More

How to copy a String into another String in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 543 Views

In C#, there are several ways to copy a string into another string. Strings in C# are immutable, meaning they cannot be changed after creation. When you "copy" a string, you create a new string object with the same value. Syntax Following are the common syntaxes for copying strings in C# − // Using String.Copy() method string str2 = String.Copy(str1); // Using direct assignment string str2 = str1; // Using string constructor string str2 = new string(str1.ToCharArray()); Using String.Copy() Method The String.Copy() method creates a new string object with the same ...

Read More

Remove all elements from OrderedDictionary in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 175 Views

The OrderedDictionary class in C# provides the Clear() method to remove all elements from the collection. This method is efficient and maintains the structure of the OrderedDictionary while removing all key-value pairs. The OrderedDictionary combines features of both Hashtable and ArrayList, allowing access to elements by both key and index while preserving insertion order. Syntax Following is the syntax for the Clear() method − public void Clear() Parameters The Clear() method takes no parameters. Return Value The Clear() method does not return any value. It simply removes all elements from ...

Read More

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

Ankit kumar
Ankit kumar
Updated on 17-Mar-2026 470 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

Remove all elements from the ArrayList in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 237 Views

To remove all elements from an ArrayList in C#, you can use the Clear() method. This method removes all elements from the ArrayList and sets the Count property to zero. Syntax Following is the syntax for the Clear() method − arrayList.Clear(); Parameters The Clear() method does not take any parameters. Return Value The Clear() method does not return any value. It is a void method that modifies the ArrayList in-place. Using Clear() to Remove All Elements The following example demonstrates how to use the Clear() method to remove all ...

Read More

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 591 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

How to get Sixth Element of the Tuple in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 211 Views

To access the sixth element of a Tuple in C#, you use the Item6 property. This property is available for tuples that contain six or more elements. Tuples in C# are immutable data structures that can store multiple values of different types. Syntax Following is the syntax to access the sixth element of a tuple − var sixthElement = tuple.Item6; The Item6 property returns the value stored at the sixth position in the tuple. Using Item6 Property The following example demonstrates how to create a 7-tuple and access its sixth element using ...

Read More
Showing 7001–7010 of 25,466 articles
« Prev 1 699 700 701 702 703 2547 Next »
Advertisements