Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Samual Sam
Page 18 of 151
Full Date Long Time ("F") Format Specifier in C#
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 MoreHow to use the return statement in C#?
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 MoreWhat are virtual functions in C#?
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 MoreC# program to check if string is panagram or not
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 MoreC# Program to Implement Stack with Push and Pop operations
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 MoreC# Program to find the cube of elements in a list
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 MoreWhy do we use comma operator in C#?
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 MoreTry-Catch-Finally in C#
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 MoreWorking with DateTime in C#
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 Morevolatile keyword in C#
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