Csharp Articles

Page 107 of 196

What is C# Programming?

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

C# is a modern, general-purpose, object-oriented programming language developed by Microsoft in 2000. It was created by Anders Hejlsberg and his team as part of Microsoft's .NET initiative to provide a robust, type-safe language that combines the power of C++ with the simplicity of Visual Basic. C# is designed for the Common Language Infrastructure (CLI), which consists of executable code and a runtime environment that allows various high-level languages to run on different computer platforms and architectures. The language compiles to bytecode called Common Intermediate Language (CIL), which runs on the .NET runtime. Key Features of C# ...

Read More

What is Cast Operator () in C#?

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 846 Views

The cast operator () in C# is used for explicit type conversion, converting one data type to another when an implicit conversion is not available or when you want to force a specific conversion. It requires you to explicitly specify the target type in parentheses before the value or variable. Syntax Following is the syntax for using the cast operator − (target_type) expression Where target_type is the type you want to convert to, and expression is the value or variable being converted − int result = (int) doubleValue; float floatResult = (float) ...

Read More

What is difference between internal and private modifiers in C#?

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

The internal and private access modifiers in C# control the visibility and accessibility of class members. Understanding their differences is crucial for designing well-structured applications with proper encapsulation. The internal modifier allows access within the same assembly, while private restricts access to the same class only. Both serve different purposes in controlling member visibility. Syntax Following is the syntax for internal access modifier − internal dataType memberName; internal void MethodName() { } Following is the syntax for private access modifier − private dataType memberName; private void MethodName() { } ...

Read More

What is the difference between implicit and explicit type conversion in C#?

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

Type conversion in C# refers to converting a value from one data type to another. There are two main types of conversions: implicit (automatic) and explicit (manual). Understanding when each occurs helps prevent data loss and compilation errors. Implicit Type Conversion Implicit conversions are performed automatically by the C# compiler when converting from a smaller data type to a larger one. This is safe because no data is lost in the process. Syntax smallerType variable = value; largerType newVariable = variable; // Automatic conversion Implicit Conversion Flow ...

Read More

Final local variables in C#

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

In C#, there is no direct equivalent to Java's final keyword for local variables. However, you can achieve similar behavior using the readonly keyword for fields and implicit typing with var or const for local variables that should not change after initialization. The readonly keyword allows a field to be assigned a value only once − either at the time of declaration or in the constructor. Once assigned, it cannot be modified. Syntax Following is the syntax for declaring a readonly field − readonly dataType fieldName; For local variables that should remain constant, ...

Read More

How to copy a List collection to an array?

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

To copy a C# List collection to an array, you can use several methods. The most common approaches are the CopyTo() method, the ToArray() method, or creating an array with the List constructor. Syntax Following is the syntax for using CopyTo() method − list.CopyTo(array); list.CopyTo(array, arrayIndex); Following is the syntax for using ToArray() method − T[] array = list.ToArray(); Using CopyTo() Method The CopyTo() method copies all elements from the List to an existing array starting at the specified array index − using System; using System.Collections.Generic; ...

Read More

What are the differences between a list collection and an array in C#?

George John
George John
Updated on 17-Mar-2026 541 Views

List collection is a generic class that can store any data type to create a dynamic collection. Arrays, on the other hand, store a fixed-size sequential collection of elements of the same type. Understanding the differences between these two collection types is crucial for choosing the right approach for your application. Syntax Following is the syntax for declaring and initializing a List − List listName = new List(); Following is the syntax for declaring and initializing an array − dataType[] arrayName = new dataType[size]; dataType[] arrayName = {value1, value2, value3}; ...

Read More

What are the differences between a static and a non-static class in C#?

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

A static class in C# cannot be instantiated and contains only static members, while a non-static class can be instantiated to create objects and can contain both static and instance members. The key difference is that static classes are designed for utility functions that don't require object state, whereas non-static classes represent entities that can have multiple instances with their own data. Syntax Following is the syntax for declaring a static class − public static class ClassName { public static void StaticMethod() { ...

Read More

Generics vs non-generics in C#

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

There are two main types of collections in C#: generic collections and non-generic collections. The primary difference lies in type safety, performance, and how they handle different data types. Generic Collections Generic collections are type-safe and hold elements of the same data type. They provide better performance as they avoid boxing and unboxing operations for value types. Key Features Type Safety: Compile-time type checking prevents runtime errors Better Performance: No boxing/unboxing for value types IntelliSense Support: Better code completion and error detection Common Generic Collections List − Dynamic array of type ...

Read More

Why do we use internal keyword in C#?

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

The internal keyword in C# is an access modifier that provides assembly-level access. It allows class members to be accessible within the same assembly but restricts access from other assemblies, making it ideal for creating APIs that should only be used internally within your project. Syntax Following is the syntax for declaring internal members − internal class ClassName { // class accessible within assembly only } class MyClass { internal int field; // field accessible within assembly ...

Read More
Showing 1061–1070 of 1,951 articles
« Prev 1 105 106 107 108 109 196 Next »
Advertisements