- 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.
dot net tips, DotNet tips, .Net Tips,Dot Net tips and tricks,Dot Net Solutions, OOPS Concept in C#,SQL Server, LinQ, Ajax, Java script, JQuery, Server Error details, daily .net tips and tricks , DotNet Interview Questions.
types of arguments Value Type and Reference Type
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.
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.
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?
|
||
<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.
|
||
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!
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!
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).
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:
- Making the class create a single instance of itself.
- Allowing other objects to access this instance through a class method that returns a reference to the instance. A class method is globally accessible.
- Declaring the class constructor as private so that no other object can create a new instance.
Code:
class SingletonClass
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.
Subscribe to:
Posts (Atom)