Server Side Programming Articles

Page 806 of 2109

How to compile unsafe code in C#?

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

Unsafe code in C# allows direct memory manipulation using pointers, which bypasses the .NET garbage collector's safety mechanisms. To compile unsafe code, you need to enable unsafe context compilation through specific compiler settings. Command-Line Compilation For compiling unsafe code using the command-line compiler, you must specify the /unsafe switch − csc /unsafe filename.cs For example, to compile a program named one.cs containing unsafe code − csc /unsafe one.cs Visual Studio IDE Configuration In Visual Studio, you need to enable unsafe code compilation in the project properties. Follow these steps ...

Read More

What is the difference between VAR and DYNAMIC keywords in C#?

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

The var and dynamic keywords in C# both allow you to declare variables without explicitly specifying their type, but they work very differently. The key difference is when type checking occurs — var is resolved at compile-time, while dynamic is resolved at runtime. Syntax Following is the syntax for declaring a var variable − var variableName = value; Following is the syntax for declaring a dynamic variable − dynamic variableName = value; Using var Keyword The var keyword creates statically typed variables. The compiler determines the type based on ...

Read More

How to access array elements using a pointer in C#?

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

In C#, accessing array elements using pointers requires understanding the key differences between arrays and pointers. An array name and a pointer to the same data type are not the same variable type. For example, int *p and int[] p represent different types. You can increment a pointer variable because it's not fixed in memory, but an array address is fixed in memory and cannot be incremented directly. To access array elements using pointers in C#, you must use unsafe code and the fixed statement to pin the array in memory temporarily. Syntax Following is the syntax ...

Read More

What is the difference between virtual and abstract functions in C#?

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

In C#, both virtual and abstract methods enable polymorphism but serve different purposes. Virtual methods provide a default implementation that can be overridden, while abstract methods have no implementation and must be overridden by derived classes. Understanding the difference between these two concepts is crucial for implementing proper inheritance hierarchies and achieving runtime polymorphism in your applications. Syntax Following is the syntax for declaring a virtual method − public virtual returnType MethodName() { // default implementation } Following is the syntax for declaring an abstract method − ...

Read More

C# program to convert an array to an ordinary list with the same items

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

Converting an array to a list is a common operation in C#. There are several ways to achieve this conversion, from manual iteration to using built-in methods that make the process more efficient and concise. Using Manual Loop The most straightforward approach is to create an empty list and add each array element using a loop − using System; using System.Collections.Generic; public class Program { public static void Main() { int[] arr = { 23, 66, 96, 110 }; var ...

Read More

File Permissions in C#

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

File permissions in C# are managed using the FileIOPermission class from the System.Security.Permissions namespace. This class controls the ability to access files and folders by defining what operations are allowed on specific file system resources. The FileIOPermission class is part of .NET's Code Access Security (CAS) system and helps ensure that applications only perform file operations they are explicitly granted permission to execute. Syntax Following is the syntax for creating a FileIOPermission instance − FileIOPermission permission = new FileIOPermission(PermissionState.None); permission.AllLocalFiles = FileIOPermissionAccess.Read; Following is the syntax for adding specific path permissions − ...

Read More

Pair Class in C#

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

The KeyValuePair structure in C# allows you to store a pair of related values as a single unit. It is commonly used in collections like Dictionary and can be used in lists to store paired data such as name-value combinations or key-identifier pairs. The KeyValuePair is a generic structure that provides a way to store two related pieces of data together, where TKey represents the key type and TValue represents the value type. Syntax Following is the syntax for creating a KeyValuePair − KeyValuePair pair = new KeyValuePair(key, value); Following is the syntax ...

Read More

Scope of Variables in C#

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

The scope of a variable in C# determines the region of code where a variable can be accessed and used. Understanding variable scope is crucial for writing efficient and error-free programs. C# has several levels of variable scope, each with different accessibility rules and lifetimes. Types of Variable Scope Method Level (Local Variables) Variables declared inside a method are local variables. They are only accessible within that specific method and are destroyed when the method execution completes − using System; class Program { public void TestMethod() { ...

Read More

How to clear screen using C#?

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

The Console.Clear() method in C# is used to clear the console screen and its buffer. When this method is called, the cursor automatically moves to the top-left corner of the console window, effectively giving you a clean slate to work with. Syntax Following is the syntax for the Console.Clear() method − Console.Clear(); How It Works The Console.Clear() method performs the following actions − Clears all text and content from the console window Resets the cursor position to (0, 0) — the top-left corner Preserves the current ...

Read More

Append to StringBuilder in C#

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

The Append() method in C# is used to add content to a StringBuilder object. Unlike strings, which are immutable, StringBuilder allows efficient concatenation of text without creating new string objects in memory. StringBuilder is particularly useful when you need to perform multiple string concatenations, as it provides better performance than using the + operator repeatedly. Syntax Following is the syntax for creating a StringBuilder and using the Append() method − StringBuilder sb = new StringBuilder(); sb.Append(value); The Append() method can accept various data types including string, char, int, double, and others. It returns ...

Read More
Showing 8051–8060 of 21,090 articles
« Prev 1 804 805 806 807 808 2109 Next »
Advertisements