Programming Articles

Page 826 of 2547

Aggregate method in C#

George John
George John
Updated on 17-Mar-2026 1K+ Views

The Aggregate method in C# is a powerful LINQ extension method that performs a sequential operation on all elements in a collection. It applies an accumulator function over a sequence, allowing you to perform custom aggregations like mathematical operations, string concatenations, or complex data transformations. Syntax Following are the main overloads of the Aggregate method − // Basic syntax - uses first element as seed public static TSource Aggregate( this IEnumerable source, Func func ); // With seed value public static TAccumulate Aggregate( ...

Read More

DateTime.Compare() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 50K+ Views

The DateTime.Compare() method in C# is used for comparison of two DateTime instances. It returns an integer value indicating the relationship between the two dates − 0 − If date1 is later than date2 Syntax Following is the syntax for DateTime.Compare() method − public static int Compare(DateTime d1, DateTime d2); Parameters d1 − The first DateTime instance to compare d2 − The second DateTime instance to compare Return Value The method returns an integer value − Negative integer − If d1 is earlier than ...

Read More

C# Generics vs C++ Templates

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 726 Views

C# Generics and C++ Templates both provide support for parameterized types, allowing you to write reusable code that works with different data types. However, they differ significantly in their design philosophy, capabilities, and implementation approaches. Key Differences Between C# Generics and C++ Templates Feature C# Generics C++ Templates Compilation Model Compile-time and run-time support Compile-time only Type Safety Strong type checking at compile-time Duck typing, errors at instantiation Specialization No explicit or partial specialization Full support for specialization Non-type Parameters Not supported Fully supported ...

Read More

Working with DateTime in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 933 Views

The DateTime class in C# is used to represent dates and times. It provides properties and methods to work with date and time values, perform calculations, comparisons, and formatting operations. Syntax Following is the syntax for creating DateTime objects − DateTime variableName = new DateTime(year, month, day); DateTime variableName = new DateTime(year, month, day, hour, minute, second); DateTime variableName = DateTime.Now; // current date and time DateTime variableName = DateTime.Today; // current date only Common DateTime Properties Property Description Date Gets the date component (time ...

Read More

All Method in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 409 Views

The All() extension method is part of the System.Linq namespace. Using this method, you can check whether all the elements in a collection match a certain condition or not. It returns true if all elements satisfy the condition, otherwise false. Syntax Following is the syntax for the All() method − bool result = collection.All(predicate); Parameters predicate − A function to test each element for a condition. It takes an element as input and returns a boolean value. Return Value The All() method returns true if all elements ...

Read More

C# Program to read all the lines one by one in a file

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 452 Views

The File.ReadAllLines() method in C# reads all lines from a file and returns them as a string array. This method is useful when you need to process a file line by line or access specific lines by their index. Syntax Following is the syntax for File.ReadAllLines() method − string[] lines = File.ReadAllLines(filePath); Parameters filePath − The path to the file to be read (string) Return Value Returns a string[] array containing all lines from the file. Each element represents one line from the file. Using ReadAllLines() to Read ...

Read More

How to use XmlSerializer in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 647 Views

The XmlSerializer in C# is used to convert objects to XML format (serialization) and back to objects (deserialization). This allows you to store object data in XML files or transmit data between applications in a standardized XML format. XmlSerializer provides fine-grained control over how objects are encoded into XML, including element names, attributes, and namespaces through various attributes. Syntax Following is the syntax for creating an XmlSerializer instance − XmlSerializer serializer = new XmlSerializer(typeof(ClassName)); Following is the syntax for serializing an object to XML − using (StreamWriter writer = new StreamWriter(filePath)) ...

Read More

Math.Truncate() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 754 Views

The Math.Truncate() method in C# is used to remove the fractional part of a number and return only the integral part. It works with both decimal and double data types, effectively cutting off all digits after the decimal point without rounding. Syntax The Math.Truncate() method has two overloads − public static decimal Truncate(decimal d) public static double Truncate(double d) Parameters d − A decimal or double number to truncate. Return Value Returns the integral part of the specified number. The return type matches the input parameter type (decimal returns ...

Read More

DateTime.AddMonths() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 5K+ Views

The DateTime.AddMonths() method in C# is used to add the specified number of months to the value of a DateTime instance. This method returns a new DateTime object representing the date after adding the specified months, while the original DateTime remains unchanged. Syntax Following is the syntax for the DateTime.AddMonths() method − public DateTime AddMonths(int months); Parameters months − An integer representing the number of months to add. Use positive values to add months and negative values to subtract months. The value can range from -120, 000 to 120, 000. Return Value ...

Read More

C# Single() Method

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 2K+ Views

The Single() method in C# returns the only element of a sequence. It throws an exception if the sequence is empty or contains more than one element, making it useful when you expect exactly one element. The Single() method is available in both LINQ to Objects and LINQ to Entities through the System.Linq namespace. Syntax Following is the syntax for the Single() method − public static TSource Single(this IEnumerable source); public static TSource Single(this IEnumerable source, Func predicate); Parameters source − The IEnumerable to return the single element from. predicate − ...

Read More
Showing 8251–8260 of 25,466 articles
« Prev 1 824 825 826 827 828 2547 Next »
Advertisements