Csharp Articles

Page 111 of 196

String format for Double in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 2K+ Views

The String.Format method in C# provides powerful options for formatting double values. You can control decimal places, add thousands separators, and apply various numeric formatting patterns to display doubles exactly as needed. Syntax Following is the basic syntax for formatting double values − String.Format("{0:format_specifier}", double_value) Common format specifiers for doubles − {0:0.000} // Fixed decimal places {0:0, 0.0} // Thousands separator with decimal {0:F2} // Fixed-point notation with 2 decimals {0:N2} ...

Read More

String Literal Vs String Object in C#

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

In C#, strings can be created using string literals or as string objects. Understanding the difference between these two approaches is important for memory management and performance optimization. String Literals String literals are constants enclosed in double quotes "" or prefixed with @"" for verbatim strings. They are stored in a special area of memory called the string pool, where identical string values are shared to save memory. Syntax Following is the syntax for string literals − string variableName = "string value"; string verbatimString = @"string with multiple lines or special characters"; ...

Read More

Retrieving Elements from Collection in C#

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

Collections in C# provide various ways to retrieve elements. The List collection is one of the most commonly used collections that allows you to access elements by index, retrieve specific elements, or iterate through all elements. Syntax Following is the syntax for accessing elements by index − ElementType element = list[index]; Following is the syntax for using foreach to iterate through all elements − foreach (ElementType item in list) { // process item } Using Index-Based Access You can retrieve elements from a List collection using ...

Read More

Overriding Vs Shadowing in C#

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

In C#, overriding and shadowing are two different mechanisms for changing method behavior in derived classes. Overriding provides true polymorphism using virtual methods, while shadowing (method hiding) creates a new method that hides the base class method without polymorphic behavior. Overriding Overriding allows a subclass to provide a specific implementation of a method that is already defined in its base class. It requires the base class method to be marked as virtual or abstract, and the derived class method to use the override keyword. Method Overriding Base Class ...

Read More

Virtual vs Sealed vs New vs Abstract in C#

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

In C#, virtual, sealed, new, and abstract are important keywords that control method inheritance and overriding behavior. Understanding these modifiers is crucial for implementing proper object-oriented design patterns and controlling how classes interact through inheritance. Virtual The virtual keyword allows a method in a base class to be overridden in derived classes. When a method is declared as virtual, derived classes can provide their own implementation using the override keyword. Syntax public virtual ReturnType MethodName() { // base implementation } Example using System; class Animal { ...

Read More

System.ArrayCopyTo() vs System.ArrayClone() in C#

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

The CopyTo() and Clone() methods in C# are used to copy array elements, but they work differently. The CopyTo() method copies elements from one array to an existing array at a specified index, while Clone() creates a new array that is a shallow copy of the original array. Understanding the difference between these methods is crucial for proper array manipulation and memory management in C# applications. Syntax Following is the syntax for the CopyTo() method − sourceArray.CopyTo(destinationArray, startIndex); Following is the syntax for the Clone() method − object clonedArray = sourceArray.Clone(); ...

Read More

What are rvalue and lvalue in C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 1K+ Views

In C#, expressions are categorized into two types based on their position and usage in assignment operations: lvalue and rvalue. Understanding these concepts helps in writing correct assignment statements and understanding compiler errors. Definitions lvalue − An expression that represents a memory location and can appear on either the left-hand or right-hand side of an assignment. The term "lvalue" means "left value". rvalue − An expression that represents a value and can only appear on the right-hand side of an assignment. The term "rvalue" means "right value". ...

Read More

Write a C# program to solve FizzBuzz problem

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

The FizzBuzz problem is a classic programming exercise that tests basic conditional logic and loop implementation. The problem requires printing numbers from 1 to 100 with specific substitutions based on divisibility rules. Problem Statement The FizzBuzz problem states that − Display "Fizz" instead of the number for each multiple of 3 Display "Buzz" instead of the number for each multiple of 5 Display "FizzBuzz" instead of the number for each multiple of both 3 and 5 Display the number itself if it's not a multiple of 3 or 5 FizzBuzz ...

Read More

What is a non-static class in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 1K+ Views

A non-static class in C# is a regular class that can be instantiated using the new keyword. Unlike static classes, non-static classes allow you to create multiple objects (instances) and can contain both instance members and static members. Non-static classes are the default type of class in C# and form the foundation of object-oriented programming, enabling encapsulation, inheritance, and polymorphism. Syntax Following is the syntax for declaring a non-static class − public class ClassName { // instance fields // static fields // instance ...

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
Showing 1101–1110 of 1,951 articles
« Prev 1 109 110 111 112 113 196 Next »
Advertisements