Server Side Programming Articles

Page 845 of 2109

How to create an infinite loop in C#?

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

An infinite loop is a loop that never terminates and repeats indefinitely. While infinite loops are generally undesirable in most applications, they can be useful in specific scenarios like game loops, server applications, or continuous monitoring systems. There are several ways to create infinite loops in C#, each with different syntax and use cases. Using For Loop The most common way to create an infinite loop is by manipulating the loop condition so it never becomes false − using System; class Program { static void Main(string[] args) { ...

Read More

How to create custom attributes in C#?

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

Custom attributes in C# allow you to store declarative information about program elements (classes, methods, properties, etc.) that can be retrieved at runtime using reflection. They provide metadata that doesn't affect program execution but can be used for documentation, validation, or configuration purposes. Syntax Following is the basic syntax for creating a custom attribute − [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] public class CustomAttribute : System.Attribute { // constructors and properties } Following is the syntax for applying the custom attribute − [CustomAttribute(parameters)] public class MyClass { // class ...

Read More

How to create user defined exceptions in C#?

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

In C#, you can create user-defined exceptions by deriving from the Exception class or one of its derived classes. User-defined exceptions allow you to create specific error types that are meaningful to your application domain, making error handling more precise and informative. Syntax Following is the basic syntax for creating a user-defined exception class − public class CustomExceptionName : Exception { public CustomExceptionName() : base() { } public CustomExceptionName(string message) : base(message) { } public CustomExceptionName(string message, Exception innerException) : ...

Read More

What are abstract classes in C#?

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

An abstract class in C# is a class that cannot be instantiated directly and contains one or more abstract methods that must be implemented by derived classes. Abstract classes provide a common base with shared functionality while requiring derived classes to implement specific methods with their own specialized behavior. Abstract classes are declared using the abstract keyword and serve as blueprints for related classes that share common characteristics but need different implementations for certain operations. Syntax Following is the syntax for declaring an abstract class with abstract methods − abstract class ClassName { ...

Read More

What are abstract properties in C#?

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

An abstract property in C# is a property declared in an abstract class without implementation. The derived classes must provide the actual implementation of the property accessor (get, set, or both). Abstract properties enforce a contract that ensures all derived classes implement the required property. Abstract properties are useful when you want to define a common structure across related classes but need each class to calculate or store the property value differently. Syntax Following is the syntax for declaring an abstract property − public abstract class ClassName { public abstract DataType PropertyName ...

Read More

What are the differences between public, protected and private access specifiers in C#?

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

Access specifiers in C# control the visibility and accessibility of class members. The three primary access specifiers − public, protected, and private − determine where class members can be accessed from, providing different levels of encapsulation and security. Syntax Following is the syntax for declaring members with different access specifiers − public class ClassName { public int publicField; // accessible everywhere protected int protectedField; // accessible in derived classes private int privateField; // accessible ...

Read More

What are accessors of properties in C#?

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

Properties are an extension of fields and are accessed using the same syntax. They use accessors through which the values of the private fields can be read, written or manipulated. The accessor of a property contains the executable statements that help in getting (reading or computing) or setting (writing) the property. Properties provide a controlled way to access class fields while maintaining encapsulation. Syntax Following is the syntax for property accessors in C# − public datatype PropertyName { get { return fieldName; } ...

Read More

What are Add, Remove methods in C# lists?

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

The List is a generic collection in C# that provides dynamic array functionality. The Add() and Remove() methods are fundamental operations for managing elements in a list, allowing you to add new items and remove existing ones efficiently. Syntax Following is the syntax for adding elements to a list − List listName = new List(); listName.Add(item); Following is the syntax for removing elements from a list − bool result = listName.Remove(item); listName.RemoveAt(index); Using Add() Method The Add() method appends an element to the end of the list. It increases ...

Read More

What are all the possible C# array initialization syntaxes?

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

C# provides multiple ways to initialize arrays, giving you flexibility in how you declare and populate arrays with values. Each syntax has its specific use cases depending on whether you know the array size in advance or want to provide initial values immediately. Array Initialization Syntax Options Explicit Size with Values You can specify the array size explicitly along with initial values − int[] marks = new int[5] { 99, 98, 92, 97, 95 }; Implicit Size with Values The array size can be inferred from the number of elements provided − ...

Read More

What are Base and Derived Classes in C#?

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

In C# object-oriented programming, inheritance allows you to create new classes based on existing ones. A base class (also called parent class) is the original class that provides common properties and methods. A derived class (also called child class) inherits from the base class and can access its members while adding its own specific functionality. The derived class automatically inherits all accessible members from the base class, including fields, properties, and methods, promoting code reusability and establishing an "is-a" relationship. Syntax Following is the syntax for creating a derived class in C# − class BaseClass ...

Read More
Showing 8441–8450 of 21,090 articles
« Prev 1 843 844 845 846 847 2109 Next »
Advertisements