Vinod Sebastian – B.Tech, M.Com, PGCBM, PGCPM, PGDBIO

Hi I'm a Web Architect by Profession and an Artist by nature. I love empowering People, aligning to Processes and delivering Projects.

Advertisements




Notes on C# Programming

Access Modifiers in C#

In C#, access modifiers control the visibility of classes, methods, and other members:

  • Public: Accessible by any code in the same or another assembly.
  • Private: Accessible only within the same class or struct.
  • Protected: Accessible within the same class, derived classes, or the same assembly.
  • Internal: Accessible by any code in the same assembly.
  • Protected internal: Accessible by code in the declaring assembly or derived classes in other assemblies.

Default Access Modifiers

In C#, classes are internal by default, while their members are private.

Interfaces in C#

Interfaces in C# can contain methods, properties, events, or indexers. Interface members are always public and cannot include access modifiers or be static.

Sealed Classes

A sealed class in C# cannot be inherited.

Constructor Behavior

If no constructor is explicitly defined, a default constructor is provided by the compiler.

Shadowing and Inheritance

When inheriting classes in C#, the new keyword can be used to indicate shadowing of inherited members.

Extension Methods

Extension methods allow adding new methods to existing types like integers using static classes and methods.

Named Arguments

In C#, named arguments can be used in method calls after positional arguments.

Indexers in C#

class IPAddress {
    public int[] ip;
    public int this[int index] {
        get { return ip[index]; }
        set { ip[index] = value; }
    }
}
IPAddress myIp = new IPAddress();
myIp[0] = 0;

Reference Variables and Generics

Reference variables use ref in both calling arguments and called parameters. They are commonly used in generics.

Conversion and Casting

C# provides various methods for conversions and casting, such as int.Parse for parsing integers and System.Convert.

Unmanaged Code

Unmanaged code in C# refers to code written outside the Common Language Runtime (CLR) and can be accessed using P/Invoke and COM Interop.

P/Invoke in C#

Static extern uint GetShortPathName([MarshalAs(UnmanagedType.LPStr)] string Pathname);

COM Interop

COM Interop in C# involves adding references, using dynamic data types, and utilizing interfaces for communicating with COM components.

Strings in C#

C# provides various constructors and methods for working with strings, including formatting options and immutable string behavior.

Delegates and Events

Delegates and events are powerful features in C# for implementing callbacks and event-driven programming.

Exception Handling

C# supports exception handling using try-catch blocks, custom exceptions, and serialization for cross-AppDomain exceptions.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x