Csharp Articles

Page 110 of 196

Numbers in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 351 Views

Numbers in C# are represented by various data types, with int being the most commonly used for whole numbers. The int type represents a 32-bit signed integer that can store values from -2, 147, 483, 648 to 2, 147, 483, 647. Basic Integer Operations C# supports standard mathematical operations on integers using arithmetic operators. Here's how to perform basic addition − using System; class Program { static void Main() { int x = 20; int y = 30; ...

Read More

Overriding in C#

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

Method overriding in C# enables runtime polymorphism by allowing a derived class to provide a specific implementation of a method that is already defined in its base class. This is achieved using the virtual keyword in the base class and the override keyword in the derived class. Overriding is essential for implementing dynamic polymorphism, where the method to be called is determined at runtime based on the actual object type rather than the reference type. Syntax Following is the syntax for method overriding using virtual and override keywords − // Base class with virtual method ...

Read More

Private Methods in C#

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

Private methods in C# can only be accessed within the class where they are defined. They use the private access modifier to restrict visibility and are commonly used for internal helper functionality that should not be exposed to external code. The private access specifier allows a class to hide its member variables and member functions from other functions and objects. Only methods within the same class can access private members, providing encapsulation and data hiding. Syntax Following is the syntax for declaring a private method − private returnType MethodName(parameters) { // method ...

Read More

How to reverse a String using C#?

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

In C# there are multiple ways to reverse a string. The most common approach is using the Array.Reverse() method, but you can also use other techniques like loops or LINQ methods for different scenarios. Using Array.Reverse() Method The Array.Reverse() method is the most efficient way to reverse a string. First, convert the string to a character array, then apply the reverse method − using System; class Program { static void Main(string[] args) { string str = "Amit"; ...

Read More

How to swap two numbers without using a temp variable in C#

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

Swapping two numbers without using a temporary variable can be achieved using different techniques in C#. These methods eliminate the need for extra memory allocation and demonstrate clever mathematical and bitwise operations. Using Arithmetic Operations The most common approach uses addition and subtraction operations to swap values − val1 = val1 + val2; val2 = val1 - val2; val1 = val1 - val2; Example using System; class Program { static void Main(string[] args) { int val1, val2; ...

Read More

Networking in C#

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

The .NET Framework provides a layered, extensible, and managed implementation of networking services that you can easily integrate into your applications. The System.Net namespace contains classes for network communication, web requests, DNS operations, and secure connections. Syntax To use networking classes, include the System.Net namespace − using System.Net; Creating a URI and web request − Uri uri = new Uri("http://www.example.com/"); WebRequest request = WebRequest.Create(uri); Using Uri Class The Uri class in C# provides object representation of a uniform resource identifier (URI). It helps parse and manipulate web addresses − ...

Read More

try keyword in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 374 Views

The try keyword in C# is used to define a block of code that might throw an exception. It must be followed by one or more catch blocks to handle exceptions, and optionally a finally block for cleanup code that runs regardless of whether an exception occurs. Syntax Following is the basic syntax for a try-catch block − try { // code that might throw an exception } catch (ExceptionType e) { // exception handling code } Following is the syntax with a finally block − ...

Read More

Timer in C#

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

The System.Timers.Timer class in C# generates events at specified intervals. It is useful for executing code periodically, such as updating displays, checking status, or performing background tasks. The timer can be configured to fire once or repeatedly, and provides precise control over timing intervals and event handling. Syntax Following is the syntax for creating and configuring a timer − Timer timer = new System.Timers.Timer(intervalInMilliseconds); timer.Elapsed += EventHandlerMethod; timer.Enabled = true; Following is the syntax for the event handler method − private static void EventHandlerMethod(Object source, ElapsedEventArgs e) { ...

Read More

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