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

Singleton Class



Singleton Pattern ensures that a class has only one instance and provides a global point of access to it.

Sample code:

Create a Singleton Class with a private static  object of itself. Create a constructor (either private or protected). Create a static method that returns an object of itself (Singleton class).

In Main, create 2 objects of Singleton class by calling static method created above. If you compare both objects, they are same.

In this way a singleton pattern can be applied so as to create a single instance of a class.

For more clarification, add a public string field in Singleton class. In the Main Method, assign value to string field for both objects. Now write the value of the string field to console. The string field contains the same value which is assign at last. 

Singleton provides a global, single instance by:
  1. Making the class create a single instance of itself. 
  2. Allowing other objects to access this instance through a class method that returns a reference to the instance. A class method is globally accessible.
  3. Declaring the class constructor as private so that no other object can create a new instance.
Code:

class
SingletonClass
{
  private static SingletonClass _instance;
  public string strName;
  protected SingletonClass ()
 {
  }
 /*private SingletonClass () // Any one private or protected constructor
 {
  } */

  public static SingletonClass Instance()
 {
        if (_instance == null) _instance = new SingletonClass();
        return _instance;
  }


static
void Main(string[] args)
{
     SingletonClass s1 = SingletonClass.Instance();
     SingletonClass s2 = SingletonClass.Instance();
      if (s1 == s2)
     {
           Console.WriteLine("Same Object");
     }
     else
     {
           Console.WriteLine("Different Object");
      }
      s1.strName = "Vinoth";
      s2.strName = "Harshad";
      Console.WriteLine("s1: {0}, s2: {1}",s1.strName,s2.strName);
}
} ------------------------------------------------------------------------------------ OR


public class Singleton
{
   private static Singleton instance;

   private Singleton() {}

   public static Singleton Instance
   {
      get
      {
         if (instance == null)
         {
            instance = new Singleton();
         }
         return instance;
      }
   }
}

What is the disadvantage of LINQ over stored procedures?



The disadvantage with LINQ is, it is not a precompiled statement where as stored procedures are precompiled. In case of LINQ the queries need to be compile before the execution. So according to this, I can say stored procedures are faster in performance as compared to LINQ.

What are differences between function and stored procedure?



1) Function returns only one value but procedure returns one or more than one value.
2) Function can be utilized in select statements but that is not possible in procedure.
3) Procedure can have an input and output parameters but function has only input parameters only.
4) Exceptions can be handled by try catch block in procedures but that is not possible in function.


Foxs, suggest me to improve the answer if you have any extra points.

Thanks.