Server Side Programming Articles

Page 789 of 2109

What is the difference between dynamic type variables and object type variables?

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

In C#, both dynamic and object type variables can store values of any type, but they differ significantly in how type checking is performed. Understanding this difference is crucial for writing efficient and safe C# code. The object type is the ultimate base class for all data types in C# Common Type System (CTS). It serves as an alias for System.Object class. All types in C# inherit from object, making it possible to assign any value to an object variable. The dynamic type bypasses compile-time type checking entirely. Operations on dynamic variables are resolved at runtime using the ...

Read More

Difference between prefix and postfix operators in C#?

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

The prefix and postfix operators in C# are increment (++) and decrement (--) operators that behave differently based on their position relative to the variable. The key difference lies in when the increment or decrement occurs and what value is returned. Syntax Following is the syntax for prefix operators − ++variable; // prefix increment --variable; // prefix decrement Following is the syntax for postfix operators − variable++; // postfix increment variable--; // postfix decrement Prefix Operators The prefix operator increments or decrements the variable first, ...

Read More

Inbuilt Data Structures in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 632 Views

C# provides several powerful built-in data structures that make it easier to store, organize, and manipulate collections of data. These data structures are part of the .NET Framework and offer different capabilities for various programming scenarios. The most commonly used built-in data structures include List for dynamic arrays, ArrayList for non-generic collections, Dictionary for key-value pairs, and Queue and Stack for specialized ordering operations. List The generic List is a strongly-typed collection that can dynamically resize itself. Unlike arrays, you don't need to specify the size at compile time, and it provides better type safety compared to ...

Read More

What is the difference between Read(), ReadKey() and ReadLine() methods in C#?

George John
George John
Updated on 17-Mar-2026 2K+ Views

The Console class in C# provides three different methods for reading user input: Read(), ReadKey(), and ReadLine(). Each method serves a specific purpose and returns different types of data from the standard input stream. Syntax Following are the syntaxes for the three input methods − int result = Console.Read(); // Returns ASCII value ConsoleKeyInfo keyInfo = Console.ReadKey(); // Returns key information string input = Console.ReadLine(); // Returns string Console.Read() Method The Read() method reads the next character from the ...

Read More

Infinity or Exception in C# when divide by 0?

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

When dividing by zero in C#, the behavior depends on the data type being used. Integer division by zero throws a DivideByZeroException, while floating-point division by zero returns Infinity or NaN (Not a Number) without throwing an exception. Syntax Following is the basic division syntax that can result in divide-by-zero scenarios − result = dividend / divisor; Exception handling syntax for integer division − try { result = dividend / divisor; } catch (DivideByZeroException ex) { // handle exception } Integer Division ...

Read More

What is the difference between initialization and assignment of values in C#?

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

In C#, initialization and assignment are two distinct concepts that are often confused. Understanding the difference is crucial for effective programming and memory management. Declaration vs Initialization vs Assignment Declaration creates a variable name, initialization allocates memory and sets initial values, and assignment changes the value of an already existing variable. Declaration → Initialization → Assignment Declaration int[] n; Creates variable name Initialization n = new int[5]; Allocates memory Assignment ...

Read More

What is the difference between overriding and hiding in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 2K+ Views

In C#, method overriding and method hiding (also called shadowing) are two different mechanisms for redefining parent class methods in a derived class. Method overriding uses the override keyword and provides polymorphic behavior, while method hiding uses the new keyword and creates a separate method that shadows the parent method. Syntax Following is the syntax for method overriding using the override keyword − public class BaseClass { public virtual void Method() { } } public class DerivedClass : BaseClass { public override void Method() { } } ...

Read More

Abort in C#

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

The Thread.Abort() method in C# is used to forcibly terminate a thread by throwing a ThreadAbortException. This method was commonly used in older versions of .NET Framework but is now deprecated and not supported in .NET Core and .NET 5+. Important Note: Thread.Abort() is considered unsafe and unreliable. Modern C# applications should use cooperative cancellation with CancellationToken instead. Syntax Following is the syntax for using Thread.Abort() − thread.Abort(); The method throws a ThreadAbortException that can be caught, but the thread will still terminate − try { // thread ...

Read More

Retrieve data value as a pointer in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 971 Views

A pointer is a variable whose value is the address of another variable. In C#, pointers can only be used in unsafe contexts. To retrieve the data stored at the location referenced by the pointer variable, you can use the dereference operator * or call the ToString() method on the pointer. Syntax Following is the syntax for declaring and using pointers in C# − unsafe { int* ptr = &variable; // Declare pointer and get address int value = *ptr; ...

Read More

Sorting a HashMap according to keys in C#

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

In C#, the equivalent of Java's HashMap is the Dictionary class, which stores key-value pairs. Sorting a Dictionary by keys requires extracting the keys, sorting them, and then accessing the values in the sorted order. Syntax Following is the syntax for creating and sorting a Dictionary by keys − Dictionary dict = new Dictionary(); // Sort keys using LINQ var sortedByKeys = dict.OrderBy(x => x.Key); // Or extract and sort keys manually var keys = dict.Keys.ToList(); keys.Sort(); Using LINQ OrderBy Method The most efficient way to sort a Dictionary by keys ...

Read More
Showing 7881–7890 of 21,090 articles
« Prev 1 787 788 789 790 791 2109 Next »
Advertisements