Garbage collection



Basically, the objects have a reference count. The object's reference-count gets zero when there is no longer reference.

If object's reference count is zero, it is marked for garbage collection. Garbage collector picks up these objects for deletion, and frees up space.

Additionally want to know this:
What is difference between Eval() and Bind()
 

types of arguments Value Type and Reference Type

  • Call by Value – Value passed will get modified only inside the function , and it returns the same value whatever it is passed it into the function.
  • Call by Reference – Value passed will get modified in both inside and outside the functions and it returns the same or different value.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ValRefType
{
    class Program
    {
        public void ValueTypeSWAP(string s,string s1)
        {
            string temp = s1;
            s1 = s;
            s = temp;
            Console.WriteLine("Swaping Name,SurName: {0} {1}", s, s1);
       
        }
        public void ReferenceTypeSWAP(ref string s,ref string s1)
        {
            string temp = s1;
            s1 = s;
            s = temp;
            Console.WriteLine("Swaping Name,SurName: {0} {1}", s, s1);

        }
        static void Main(string[] args)
        {
            string name = "vinoth";
            string fatname = "myilsamy";
            Console.WriteLine("Original Name,SurName: {0} {1}", name, fatname);
            Program Pro = new Program();
            Pro.ValueTypeSWAP(name, fatname);
            Console.WriteLine("Value Type After Swaped Name,SurName: {0} {1}", name, fatname);

            Pro.ReferenceTypeSWAP(ref  name, ref  fatname);
            Console.WriteLine("Ref Type After Swaped Name,SurName: {0} {1}", name, fatname);
            Console.ReadKey();
        }
    }
}

What is Assemblies and types

Assemblies are two types
They are Shared assembly and private assembly.
shared assemblies are shared among multiple applications and they are stored in Global Assembly Cache.
Private Assemblies implies to a single application and they are stored in the root directory of the application.

GAC:
===
GAC is used to store assemblies and to share them between multiple applications. IN the shared system, the names of the assemblies should be unique as it can be accessed by all applications. The newer versions of the component should also have unique names. These can be achieved by using a strong name for the assembly. A shared assembly is placed in the GAC folder that is reserved for shared assemblies.

GACUtil:
=======
Global assemblies will be registered in C:\windows\Assembly as
GAC(Global Assembly Cache) using a tool called GACUtil. Once
it is registered, any application can refer for that
assembly to that path.

Early Binding vs Late Binding

Early Binding

Early Binding describes that compiler knows about what kind of object it is, what are all the methods and properties it contains. As soon as you declared the object, .NET Intellisense will populate its methods and properties on click of the dot button.

Late Binding

Late Binding describes that compiler does not know what kind of object it is, what are all the methods and properties it contains. You have to declare it as an object, later you need get the type of the object, methods that are stored in it. Everything will be known at the run time.

Difference

    Application will run faster in Early binding, since no boxing or unboxing are done here.

    Easier to write the code in Early binding, since the intellisense will be automatically populated

    Minimal Errors in Early binding, since the syntax is checked during the compile time itself.

    Late binding would support in all kind of versions, since everything is decided at the run time.

    Minimal Impact of code in future enhancements, if Late Binding is used.

    Performance will be code in early binding.

Exception handling in asp.net



What is an Exception?
An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. 

What are the different approaches to handle exceptions in asp.net web application?
  1. Use exception-handling structures to deal with exceptions within the scope of a procedure.
    try { ---- }
    catch { ---- }
    finally { -----}
  2. Use error events to deal with exceptions within the scope of an object.
    Page_Error - The Page_Error event handler provides a way to trap errors that occur at the page level.
    Application_Error - Application_Error event handler to trap errors that occur at the application level.
  3. Custom error pages to display custom error pages for unhandled exceptions at application level.
<customErrors mode="RemoteOnly" defaultRedirect="~/errors/GeneralError.aspx" redirectMode="ResponseRewrite" /> the ResponseRewrite mode allows us to load the Error Page without redirecting the browser, so the URL stays the same, and importantly for me, exception information is not lost.

What will happen if an exception occur inside try block?
If a code in a try block causes an exception, control flow passes to immediate catch or finally block. 

What is the main use of finally block in exception handling?
Finally block is mainly used to free resources used within the try block.(Ex: closing db connections, and file connection ...)

Will the finally block get executed, if an exception doesn't occurs?
Yes, a finally block will always be executed irrespective of whether an exception has occured or not. 

Can multiple catch blocks be executed?

No, Multiple catch blocks can’t be executed. Once the proper catch code executed, the control is transferred to the finally block and then the code that follows the finally block gets executed.




advantage of LINQ over stored procedures

1. Debugging - It is really very hard to debug the Stored procedure but as LINQ is part of .NET, you can use visual studio's debugger to debug the queries.

2. Deployment - With stored procedures, we need to provide an additional script for stored procedures but with LINQ everything gets complied into single DLL hence deployment becomes easy.

3. Type Safety - LINQ is type safe, so queries errors are type checked at compile time. It is really good to encounter an error when compiling rather than runtime exception!

Difference between Eval() and Bind()?

Eval(): -

Eval() method proviedes only for displaying data from a datasource in a control.

Bind():-


Bind() methods provides for two-way binding which means that it cannot be used to dispaly as well update data from a datasource