Server Side Programming Articles

Page 786 of 2109

Swap two Strings without using temp variable in C#

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

To swap two strings without using a temporary variable in C#, you can use string concatenation and the Substring() method. This technique works by combining both strings into one, then extracting the original values in reverse order. Algorithm The swapping process follows these three steps − Step 1: Append the second string to the first string. Step 2: Extract the original first string from the beginning and assign it to the second string variable. Step 3: Extract the original second string from the remaining part and assign it to the first string variable. ...

Read More

Static vs. Non-Static method in C#

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

In C#, methods can be declared as either static or non-static (instance methods). Static methods belong to the class itself and can be called without creating an instance of the class, while non-static methods belong to specific instances of the class. Static methods can only access static variables and other static members directly. They exist even before any object of the class is created and are shared across all instances of the class. Syntax Following is the syntax for declaring a static method − public static returnType MethodName() { // method ...

Read More

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 407 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 402 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
Showing 7851–7860 of 21,090 articles
« Prev 1 784 785 786 787 788 2109 Next »
Advertisements