Sunday, July 1, 2012

GetCommandLineArgs() method in C# .NET


What is the use of GetCommandLineArgs() method in C#.NET?


With GetCommandLineArgs() method, the command line arguments can be accessed. 
The value returned is an array of strings.

Compare C# .NET Generics and C++ Templates


How does C#.NET Generics and C++ Templates compare?


C# generics and templates in C++ are more or less similar syntactically.


C# Generic types are strong typed. C++ Templates are loosely typed.
C# Generic types are instantiated at the runtime. C++ templates are instantiated at the compile time.
C# Generic types do not permit the type parameters to have default values. C++ templates do.

Achieve polymorphism in C# .NET


How to achieve polymorphism in C#.NET?


Polymorphism is when a class can be used as more than one type through inheritance. It can be used as its own type, any base types, or any interface type if it implements interfaces.It can be achieved in the following ways.


Derived class inherits from a base class and it gains all the methods, fields, properties and events of the base class.


To completely take over a class member from a base class, the base class has to declare that member as virtual.

Use of System.Environment class in C# .NET


What is the use of System.Environment class in C#.NET?


The System.Environment class can be used to retrieve information like below :

  • Command-line arguments.
  • The exit code.
  • Environment variable settings.
  • Contents of the call stack.
  • Time since last system boot.
  • The version of the common language runtime.


Prevent class from being inherited in C#.NET


How to prevent a class from being inherited in C#.NET?


The sealed modifier is used to prevent derivation from a class. An error occurs if a sealed class is specified as the base class of another class. A sealed class cannot also be an abstract class.