Samual Sam

Samual Sam

1,507 Articles Published

Articles by Samual Sam

Page 18 of 151

Full Date Long Time ("F") Format Specifier in C#

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

The Full Date Long Time ("F") format specifier in C# displays a complete date and time representation in a long format. This format specifier uses the current culture's DateTimeFormatInfo.FullDateTimePattern property to determine the exact format string. The "F" specifier provides the most comprehensive date and time display, showing the full day name, complete date, and precise time including seconds. Syntax Following is the syntax for using the "F" format specifier − DateTime.ToString("F") DateTime.ToString("F", CultureInfo) The default custom format string for "F" is − dddd, dd MMMM yyyy HH:mm:ss Using ...

Read More

How to use the return statement in C#?

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

The return statement in C# is used to exit a method and optionally return a value to the caller. When a method contains a return statement, the program control immediately transfers back to the calling method along with the specified return value. Syntax Following is the syntax for using the return statement − return; // For void methods (no value returned) return expression; // For methods that return a value Using Return Statement with Value Types When a method has a return type other than void, it must return a ...

Read More

What are virtual functions in C#?

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

The virtual keyword in C# allows a method, property, indexer, or event to be overridden in derived classes. Virtual functions enable runtime polymorphism, where the actual method called is determined at runtime based on the object's type, not the reference type. When you define a virtual function in a base class, derived classes can provide their own implementations using the override keyword. This allows different derived classes to implement the same method differently while maintaining a common interface. Syntax Following is the syntax for declaring a virtual method − public virtual returnType MethodName() { ...

Read More

C# program to check if string is panagram or not

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

A pangram is a sentence that contains all 26 letters of the English alphabet at least once. The word "pangram" comes from Greek, meaning "all letters". A famous example is "The quick brown fox jumps over the lazy dog". In C#, we can check if a string is a pangram by converting it to lowercase, filtering only alphabetic characters, and counting the distinct letters present. Syntax The basic approach uses LINQ methods to process the string − string.ToLower().Where(ch => Char.IsLetter(ch)).GroupBy(ch => ch).Count() This checks if the count of distinct letters equals 26. ...

Read More

C# Program to Implement Stack with Push and Pop operations

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

A Stack in C# is a Last-In-First-Out (LIFO) data structure that allows elements to be added and removed from only one end, called the top. The Stack class in the System.Collections namespace provides built-in methods for implementing stack operations. The two primary operations of a stack are Push() to add elements and Pop() to remove elements. Additionally, the Peek() method allows you to view the top element without removing it. Syntax Following is the syntax for creating a Stack and using basic operations − Stack stackName = new Stack(); stackName.Push(element); // ...

Read More

C# Program to find the cube of elements in a list

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

This program demonstrates how to find the cube of each element in a list using the Select() method with a lambda expression. The Select() method transforms each element in the collection by applying a specified function. Syntax Following is the syntax for using Select() method with lambda expression − collection.Select(x => expression) For calculating the cube of each element − list.Select(x => x * x * x) Using Select() Method to Calculate Cube The Select() method applies a transformation function to each element in the list. In this case, ...

Read More

Why do we use comma operator in C#?

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

The comma operator in C# serves as a separator and allows multiple operations within a single statement. It is most commonly used in for loops for multiple variable initialization and increment operations, and as a separator in method parameter lists. Syntax Following is the syntax for using comma operator in for loop initialization and increment − for (int i = value1, j = value2; condition; i++, j++) { // loop body } Following is the syntax for using comma as separator in method parameters − MethodName(parameter1, parameter2, parameter3); ...

Read More

Try-Catch-Finally in C#

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

The try-catch-finally statement in C# provides a structured way to handle exceptions that may occur during program execution. It allows you to gracefully handle errors like division by zero, file access failures, or network timeouts without crashing your application. Exception handling in C# is performed using three main keywords that work together to create a robust error handling mechanism. Syntax Following is the basic syntax of try-catch-finally statement − try { // Code that may throw an exception } catch (ExceptionType ex) { // Handle the exception } finally ...

Read More

Working with DateTime in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 932 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

volatile keyword in C#

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

The volatile keyword in C# is used to indicate that a field might be modified by multiple threads that are executing at the same time. It ensures that the most recent value of a field is present on each read operation, preventing certain compiler optimizations that could lead to unexpected behavior in multithreaded environments. When a field is marked as volatile, the compiler and runtime ensure that reads and writes to that field are not cached or reordered, providing thread-safe access without explicit locking mechanisms. Syntax Following is the syntax for declaring a volatile field − ...

Read More
Showing 171–180 of 1,507 articles
« Prev 1 16 17 18 19 20 151 Next »
Advertisements