What are the advantages of C# (C Sharp)?

-> C# provides operator overloading which is not available in VB.NET




-> C# allows you to access memory directly using unsafe code blocks

-> If you use unmanaged resources in your program, then garbage collector will not dispose it. For disposing unmanaged resources, C# permits you to use "using" statement

-> C# allows you to implement an interface in a base class and re-implement the interface in the derived class and provide a new definition for it C# permits nested classes which are not allowed in C and C++

-> C# establishes better event management using delegates

-> C# allows you to document your code using XML documentation

-> C# gets rid of complex registry lookups and problems due to IDispatch, IUnknown of COM by introducing the concept of namespaces

-> C# supports cross-language interoperability with any .NET language

-> C# supports conditional compilation

-> Most important advantage of C# is the reflection mechanism.

Consider the following example:

class sampleClass {
public void sampleMethod() {
Console.WriteLine("Invoking sampleMethod of sampleClass");
}
}

Now you have to invoke and execute the method sampleMethod of sampleClass. How do you do it? Here is the normal way of coding which all of you might perform:

class testClass {
public static void Main() {
sampleClass obj = new sampleClass();
obj.sampleMethod();
}
}

C# provides an advanced feature called reflection mechanism using which you can invoke sampleMethod as shown below:

class testClass {
public static void Main() {
sampleClass obj = new sampleClass();
Type sampleType = Type.GetType("sampleClass");
object obj = Activator.CreateInstance(sampleType);
sampleType.InvokeMember(
"sampleMethod", BindingFlags.InvokeMethod, null, obj, null);

}
}

This is just a simple example, reflection mechanism can be used to establish dynamic behavior and determine all properties and methods of an object at runtime and much more.


Add to My Yahoo!


FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

Visit .NET Programming Tutorial Homepage

______________________________________________________

Recommended Resource

| How do you prevent a class from overriding in .NET? | How are classes related to objects in .NET Application | How are Delegates different from Events in .NET? | How are system exceptions different from application exceptions in .NET? | How are Value Types different from Reference Types in .NET? | How can a finalize method be suppressed in .NET? | How can you call Stored Procedure in ADO.NET? | How can you force Dispose method to be called automatically in .NET? | How do you call a Base Class Constructor from Derived Class Constructor in .NET? | How do you connect your VB.NET application to SQL Server? | How do you implement Cloning in .NET? | How do you implement Façade Design Pattern in .NET? | How do you implement MVC Pattern in ASP.NET? | How do you install .NET Assembly in GAC? | How is shadowing different from overriding in .NET? | How to prevent a particular .NET DLL from being decompiled? | Illustrate Delay Signing Process of an Assembly in .NET? | What are Reference Types in .NET? | What are the advantages of C#? | What are the advantages of VB.NET? | What are the differences between Namespace and Assembly in .NET? | What are the similar features between class and structure in .NET? | What are Value Types in .NET? | What do you mean by mixed mode authentication in .NET? | What do you mean by Satellite Assembly in .NET? | What do you mean by shadowing in .NET? | What is CTS in .NET? | What is ILDASM in .NET? | What is Managed Code in .NET? | What is Manifest in .NET? | What is MSIL in .NET Framework? | What is the importance of finalize method in .NET? | What is the need for Visitor Pattern in C#? | What is the purpose of bindingRedirect tag in web.config file of .NET? | What is the purpose of CodeDom in .NET? | What is the purpose of dispose method in .NET? | What is the purpose of Ngen.exe in .NET? | What is the purpose of Strong Name in COM Components of .NET? | What is the purpose of virtual keyword in .NET? | What Object Oriented Principles can be incorporated in .NET Application? |


| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2018 - All Rights Reserved.