.Net framework is a set of integrated features or tools to develop the application in faster and quicker way. It provides the robust and secure platform to develop and deploy the application.
.net framework can be used to develop/deploy Windows ,Web,Mobile based applications as well as it provides the all desired infrastructure for component based and web services based applications.
Garbage Collector:-
The Garbage Collector is a part of CLR, The garbage collector (GC) in .NET is a core part of the .NET Common Language Runtime (CLR) and is available to all .NET programming languages. The GC was never meant to manage resources; it was designed to manage memory allocation, and it does an excellent job at managing memory allocated directly to native .NET objects. It was not designed to deal with unmanaged memory and operating system allocated memory, so it becomes the responsibility of the developer to manage these resources.
It will be triggered in following conditions.
- When Memory is full.
- When CLR is going to close.
- The app domain shutdown.
- gc.collect is executed, it just request to garbage collector to collect all the garbage, but cannot force it.
As soon as Garbage Collector is start, It will halt the application with the help of CLR. The CLR will check the state of all the running applications either its in safe or not. safe state means application should not be in any critical section or should not be using or waiting for any system resources.
As soon as It finds that all the applications are in safe state, It will hijack the applications session and give the control to GC.
The GC will now evaluate all the process from starting point and mark all the referenced and un-referenced memory blocks. GC will invoke the "Finalize" method to do the cleanup.
After doing this it will over right the unused block with there neighbor used block and shift them, so that all unused memory will left at one place(It will resolve the memory fragmentation issues also).
This is call un-deterministic memory management. If we think carefully really the execution of garbage collection is happened in a life cycle of a program is very rare :-)
As system rarely goes with out of memory, there is no actual impact of your gc.collect() in garbage collection
The CLR does provide a way to implement deterministic finalization through the IDisposable interface, a "Dispose" method for explicit cleanup, and in some cases, a "Finalize" method for implicit cleanup. This is commonly referred to as the Dispose Pattern (or the IDisposable Pattern).
IDisposable interface is looks like as:-
public interface IDisposable
{
void Dispose();
}
The following code shows how we can use it.
public class MyClass : IDisposable
{
public void Dispose()
{
// Perform object clean up here.
}
}
The
SafeHandle class has implementation of Finalize method. So implementation of Finalize method is now rarely needed. If you wish to implement it, you can implement the protected Finalize method using the language specific syntax. The runtime will call Finalize for you non-deterministically as part of the GC's finalization process, providing a last chance for your object to release resources at the end of its lifetime.
You really don’t require a finalizer. As Garbage collector will automatically dispose the un-used objects, the Writing it properly will be a very difficult task. We know that GC is rarely called means Finalize will also called rarely J , The GC will maintain a list of all objects that that implement a finalizer, called the finalization queue .
When you are going to cleanup for your resources, It must be in dispose method, not in Finalizer. If you need a finalizer, it must be in addition not instead of Dispose.
What is Code
Access Security (CAS)? How does CAS work? Who defines the CAS code groups?
Code
Access Security (CAS) is part of the .NET security model. CAS determines
whether or not a piece of code is allowed to run and also what resources to
use. For example, CAS will prevent malicious code from entering your system and
causing havoc.
The CAS security policy revolves around two key concepts - code groups and permissions. Each .NET assembly is a member of a particular code group and each code group is granted the permissions specified in a named permission set. An example: Using the default security policy, a control downloaded from a web site belongs to the 'Zone - Internet' code group which complies to the permissions defined by the 'Internet' named permission set.
Microsoft defines some default policies but you can modify these and even create your own. To view the code groups defined on your system; Run 'caspol' from the command-line and checkout the different options on display.
What is Code
Access Security (CAS)? How does CAS work? Who defines the CAS code groups?
Code
Access Security (CAS) is part of the .NET security model. CAS determines
whether or not a piece of code is allowed to run and also what resources to
use. For example, CAS will prevent malicious code from entering your system and
causing havoc. The CAS security policy revolves around two key concepts - code groups and permissions. Each .NET assembly is a member of a particular code group and each code group is granted the permissions specified in a named permission set. An example: Using the default security policy, a control downloaded from a web site belongs to the 'Zone - Internet' code group which complies to the permissions defined by the 'Internet' named permission set.
Microsoft defines some default policies but you can modify these and even create your own. To view the code groups defined on your system; Run 'caspol' from the command-line and checkout the different options on display.
What is C#?
C# is a new programming language introduced with the
Microsoft .NET framework and is no doubt the language of choice in .NET
environment. It is an
Object Oriented Programming language, which at its core, has similarities with
Java, C++ and VB. In fact, C# combines the power & efficiency of C++, simple & clean OO design of Java, and code simplification of Visual Basic. Like Java, C# also does not allow multiple inheritance and use of pointers (in safe and managed code) while it does provide garbage memory collection at runtime. But, contrary to java, C# keeps the different useful concepts of C++ like operator overloading, enumerations, pre-processor directives, pointers (in unmanaged and un-safe code), function pointers (in the form of delegates), also have template support (with the name of generics) . Like VB it also supports the concepts of properties .
In addition to this, C# comes up with some new/exciting features like reflections, attributes, marshaling, remoting, threads, streams, data access with ADO.NET, etc. C# programming language is designed from the scratch keeping in mind the Microsoft.Net environment. MS.Net (and thus C#) programs runs on top of the Common Language Runtime (CLR), which provides the runtime support to them.
Here is the sample C# Program.
Sample C# Application
Using System
Class Sample
{
public static void main()
{
Console.WriteLine (“Hello World”)
}
}