Samual Sam

Samual Sam

1,507 Articles Published

Articles by Samual Sam

Page 21 of 151

C# Linq Sum() Method

Samual Sam
Samual Sam
Updated on 17-Mar-2026 11K+ Views

The LINQ Sum() method in C# is used to calculate the sum of numeric values in a collection. It works with various numeric types including int, double, decimal, and float, and can also work with nullable types. Syntax Following is the basic syntax for the Sum() method − // For basic numeric collections collection.Sum() // With a selector function collection.Sum(selector) Parameters The Sum() method has the following parameter − selector (optional) − A function to extract numeric values from each element. Return Value Returns the sum of ...

Read More

How do we call a C# method recursively?

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

Recursion in C# is a programming technique where a method calls itself to solve a smaller version of the same problem. Each recursive call reduces the problem size until it reaches a base case that stops the recursion. A recursive method must have two essential components: a base case that stops the recursion, and a recursive case that calls the method with modified parameters. Syntax Following is the general syntax for a recursive method − public returnType MethodName(parameters) { if (baseCondition) { return baseValue; ...

Read More

C# Program to get information about a file

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

To get information about a file means to retrieve the attributes and properties associated with that particular file. File attributes indicate characteristics such as whether a file is normal, hidden, archived, read-only, or a system file. In C#, the FileInfo class provides comprehensive information about files, including attributes, size, creation time, and modification time. Syntax Following is the syntax for creating a FileInfo object and getting file attributes − FileInfo info = new FileInfo("filename.txt"); FileAttributes attr = info.Attributes; Using FileInfo to Get File Attributes The FileAttributes enumeration represents various file attributes that ...

Read More

How do you use a 'for loop' for accessing array elements in C#?

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

The for loop in C# executes a sequence of statements multiple times and is commonly used to iterate through arrays. It provides a clean way to access and manipulate array elements using an index variable that increments automatically. Syntax Following is the syntax for a for loop used with arrays − for (int i = 0; i < arrayName.Length; i++) { // Access array element using arrayName[i] } The for loop has three parts − Initialization: int i = 0 sets the starting index Condition: i < arrayName.Length continues ...

Read More

C# Program to get the last access time of a file

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

To get the last access time of a file in C#, you can use the LastAccessTime property of the FileInfo class or the static File.GetLastAccessTime() method. The last access time represents when the file was last opened or read. Syntax Using the FileInfo class − FileInfo fileInfo = new FileInfo("filepath"); DateTime lastAccess = fileInfo.LastAccessTime; Using the static File.GetLastAccessTime() method − DateTime lastAccess = File.GetLastAccessTime("filepath"); Using FileInfo Class The FileInfo class provides an object-oriented approach to working with files. Here's how to get the last access time − ...

Read More

C# Program to convert Digits to Words

Samual Sam
Samual Sam
Updated on 17-Mar-2026 4K+ Views

Converting digits to words in C# involves breaking down a number into its individual digits and mapping each digit to its corresponding word representation. This technique is commonly used in financial applications, report generation, and number-to-text conversion systems. Algorithm Overview The conversion process follows these steps − Create an array of word strings for digits 0-9 Extract each digit from the number using modulo operation Store digits in reverse order (rightmost digit first) Map each digit to its corresponding word and display in correct order Digit-to-Word Conversion Process ...

Read More

What are multicasting delegates in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

A multicasting delegate in C# is a delegate that holds references to multiple methods. When invoked, it calls all the methods in its invocation list sequentially. This is achieved using the += operator to add methods and -= operator to remove methods from the delegate. Multicasting delegates are particularly useful for implementing event-like behavior where multiple handlers need to be executed when a single event occurs. Syntax Following is the syntax for declaring a multicasting delegate − delegate returnType DelegateName(parameters); Adding and removing methods from a multicasting delegate − DelegateName del ...

Read More

What is the difference between an interface and an abstract class in C#?

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

In C#, both interfaces and abstract classes provide a way to define contracts that derived classes must follow. However, they serve different purposes and have distinct characteristics that make them suitable for different scenarios. An interface defines a contract specifying what methods, properties, and events a class must implement, but provides no implementation itself. An abstract class can provide both abstract members (without implementation) and concrete members (with full implementation). Interface Syntax Following is the syntax for declaring an interface − public interface IInterfaceName { void MethodName(); string PropertyName ...

Read More

Lowercase suffixes in C#

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

In C#, lowercase suffixes are used with numeric literals to specify their data type explicitly. These suffixes tell the compiler to treat the literal as a specific numeric type rather than inferring the type automatically. Syntax Following are the common lowercase suffixes used with numeric literals − long number = 12345l; // l for long float number = 3.14f; // f for float uint number = 100u; // u for unsigned int ulong number = 500ul; ...

Read More

C# Program to Convert Fahrenheit to Celsius

Samual Sam
Samual Sam
Updated on 17-Mar-2026 3K+ Views

Temperature conversion between Fahrenheit and Celsius is a common programming task. In C#, you can easily convert Fahrenheit to Celsius using a simple mathematical formula and display the results with proper formatting. The conversion formula subtracts 32 from the Fahrenheit temperature, then multiplies by 5/9 to get the equivalent Celsius temperature. Formula The mathematical formula for converting Fahrenheit to Celsius is − celsius = (fahrenheit - 32) * 5 / 9 Fahrenheit to Celsius Conversion 97°F - 32 × 5/9 ...

Read More
Showing 201–210 of 1,507 articles
« Prev 1 19 20 21 22 23 151 Next »
Advertisements