Mention
what “beforFilter()”,“beforeRender” and “afterFilter” functions do in
Controller?
- beforeFilter(): This function is run before every action in the controller. It’s the right place to check for an active session or inspect user permissions.
- beforeRender(): This function is called after controller action logic, but before the view is rendered. This function is not often used, but may be required If you are calling render() manually before the end of a given action
- afterFilter(): This function is called after every controller action, and after rendering is done. It is the last controller method to run
Mention
what is the importance of NonActionAttribute?
·
All
public methods of a controller class are treated as the action method if you
want to prevent this default method then you have to assign the public method
with NonActionAttribute.
What
is the difference between “dispose” and “finalize” variables in C#?
- Dispose - This method uses interface – “IDisposable” interface and it will free up both managed and unmanaged codes like – database connection, files etc.
- Finalize - This method is called internally unlike Dispose method which is called explicitly. It is called by garbage collector and can’t be called from the code. This method is used for garbage collection. So before destroying an object this method is called as part of clean up activity.
Explain “static” keyword in C#?
“Static” keyword can be used for
declaring a static member. If the class is made static then all the members of
the class are also made static. If the variable is made static then it will
have a single instance and the value change is updated in this instance.
Explain
Instance in C#?
Instance is to class as
cake is to recipe. Any time you use a constructor to create an object, you are
creating an instance.
What
is the difference between “constant” and “readonly” variables in C#?
- “Const” keyword is used for making an entity constant. We cannot modify the value later in the code. Value assigning is mandatory to constant variables.
- “readonly” variable value can be changed during runtime and value to readonly variables can be assigned in the constructor or at the time of declaration.
Why
to use “finally” block in C#?
“Finally” block will be executed irrespective of exception.
So while executing the code in try block when exception is occurred, control is
returned to catch block and at last “finally” block will be executed. So
closing connection to database / releasing the file handlers can be kept in
“finally” block.
What
is the difference between “throw ex” and “throw” methods in C#?
- “throw ex” will replace the stack trace of the exception with stack trace info of re throw point.
- “throw” will preserve the original stack trace info.
What
is the difference between “out” and “ref” parameters in C#?
“out” parameter can be passed to a
method and it need not be initialized where as “ref” parameter has to be
initialized before it is used.
What
is the difference between “StringBuilder” and “String” in C#?
- StringBuilder is mutable, which means once object for stringbuilder is created, it later be modified either using Append, Remove or Replace.
- String is immutable and it means we cannot modify the string object and will always create new object in memory of string type.
Explain
Generics in C#?
Generics in c# is used to make the
code reusable and which intern decreases the code redundancy and increases the
performance and type safety.
Namespace – “System.Collections.Generic” is available in C# and this should be used over “System.Collections” types.
Namespace – “System.Collections.Generic” is available in C# and this should be used over “System.Collections” types.
What
is Nullable Types in C#?
Variable types does
not hold null values so to hold the null values we have to use nullable types.
So nullable types can have values either null or other values as well.
Eg: Int? mynullablevar =
null;
What
is the difference between “as” and “is” operators in C#?
- “as” operator is used for casting object to type or class.
- “is” operator is used for checking the object with type and this will return a Boolean value
What
you mean by boxing and unboxing in C#?
Boxing – This is the process of
converting from value type to reference type. For example,
int myvar = 10;
object myObj = myvar;
object myObj = myvar;
UnBoxing – It’s completely
opposite to boxing. It’s the process of converting reference type to value
type. For example,
int myvar2 = (int)myObj;
Explain
Attributes in C#?
- Attributes are used to convey the info for runtime about the behavior of elements like – “methods”, “classes”, “enums” etc.
- Attributes can be used to add metadata like – comments, classes, compiler instruction etc.
List
out the pre-defined attributes in C#?
Below
are the predefined attributes in C# -
- Conditional
- Obsolete
- Attribute Usage
What
is Operator Overloading in C# .net?
We
had seen function overloading in the previous example. For operator overloading,
we will have a look at the example given below. We had defined a class
rectangle with two operator overloading methods.
class Rectangle
{
private int Height;
private int Width;
public Rectangle(int w,int h)
{
Width=w;
Height=h;
}
public static bool operator >(Rectangle
a,Rectangle b)
{
return a.Height > b.Height ;
}
public static bool operator <(Rectangle
a,Rectangle b)
{
return a.Height < b.Height ;
}
}
Let
us call the operator overloaded functions from the method given below. When
first if condition is triggered, the first overloaded function in the rectangle
class will be triggered. When second if condition is triggered, the second
overloaded function in the rectangle class will be triggered.
public static void Main()
{
Rectangle obj1 =new
Rectangle();
Rectangle obj2 =new
Rectangle();
if(obj1 > obj2)
{
Console.WriteLine("Rectangle1 is greater
than Rectangle2");
}
if(obj1 < obj2)
{
Console.WriteLine("Rectangle1 is less
than Rectangle2");
}
}
What
is Data Encapsulation?
Data
Encapsulation is defined as the process of hiding the important fields from the
end user. In the above example, we had used getters and setters to set value
for MinSalary. The idea behind this is that, private field “minimumSalary” is
an important part of our classes. So if we give a third party code to have
complete control over the field without any validation, it can adversely affect
the functionality. This is inline with the OOPS Concept that an external user
should know about the what an object does. How it does it, should be decided by
the program. So if a user set a negative value for MinSalary, we can put a
validation in the set method to avoid negative values as shown below
set
{
if(value > 0)
{
minSalary = value;
}
}
Can
Multiple Inheritance implemented in C# ?
In
C#, derived classes can inherit from one base class only. If you want to
inherit from multiple base classes, use interface.
What
is overriding in c# ?
To
override a base class method which is defined as virtual, Override keyword is
used. In the above example, method DriveType is overridden in the derived class
What
is Method Hiding in C# ?
If
the derived class doesn't want to use methods in the base class, derived class
can implement it's own version of the same method with same signature. For
example, in the classes given below, DriveType() is implemented in the derived
class with same signature. This is called Method Hiding.
class Car
{
public void DriveType()
{
Console.WriteLine("Right Hand
Drive");
}
}
class Ford : Car
{
public void DriveType()
{
Console.WriteLine("Right Hand ");
}
}
What
is a Destructor in C# ?
Destructor
is a special method that get invoked/called automatically whenever an object of
a given class gets destroyed. Main idea behind using destructor is to free the
memory used by the object.
What
are difference between GET and POST Methods?
Ans:
GET Method ():
1) Data is appended to the URL.
2) Data is not secret.
3) It is a single call system
4) Maximum data that can be sent is 256.
5) Data transmission is faster
6) this is the default method for many browsers
POST Method ():
1) Data is not appended to the URL.
2) Data is Secret
3) it is a two call system.
4) There is no Limit on the amount of data. That is characters any amount of data can be sent.
5) Data transmission is comparatively slow.
6) No default and should be explicitly specified.
1) Data is appended to the URL.
2) Data is not secret.
3) It is a single call system
4) Maximum data that can be sent is 256.
5) Data transmission is faster
6) this is the default method for many browsers
POST Method ():
1) Data is not appended to the URL.
2) Data is Secret
3) it is a two call system.
4) There is no Limit on the amount of data. That is characters any amount of data can be sent.
5) Data transmission is comparatively slow.
6) No default and should be explicitly specified.
What
are difference between truncate and delete?
Ans: 1) Delete keep the
lock over each row where Truncate keeps the lock on table not on all the row.
2) Counter of the Identity column is reset in Truncate where it is not reset in Delete.
3) Trigger is not fired in Truncate whereas trigger is fired in Delete.
2) Counter of the Identity column is reset in Truncate where it is not reset in Delete.
3) Trigger is not fired in Truncate whereas trigger is fired in Delete.
4)
In TRUNCATE we cannot rollback.
5) In DELETE we can
rollback
What is
the serialization?
Ans:
Serialization
is a process of converting object into a stream of bites.
What is
Collation?
Ans:
Collation
refers to a set of rules that determine how the data is sorted and compared.
What is
the difference between Primary key and unique key?
Ans:
Primary
key does not allow the null values but unique key allows one null value.
Primary
key will create clustered index on column but unique key will create non-clustered
index by default.
How
many web.config files are there in 1 project?
Ans: There might be
multiple web.config files for a single project depending on the hierarchy of
folders inside the root folder of the project, so for each folder we can use
one web.config file
What is
the difference between view state and hidden field?
Ans:
viewstate
is secured hidden field is insecure
Viewstate
will store large amount of data but hidden filed will store small amount of
data.
To begin with using
jQuery with ASP.NET, first download the latest version the jQuery library from jQuery website and unzip or copy the
file in your project or Visual studio solution. Microsoft Visual studio 2010
and 2012 include jQuery by default and provide intellisense to use jQuery.
Assuming that you have placed the library in Script folder, add this in the
head of your ASP.NET page (simple or master). (Its a good practice to keep your
all js file under Script folder).
<script
src="Scripts/jquery-1.9.1.min.js"
type="text/javascript"></script>
Or you can directly
refer them using various CDNs. Put this line of
code in head section of ASP.NET Page.
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"
type="text/javascript"></script>
In the above code, I
have not used "http" protocol while referencing jQuery from Google
CDN. Its not a mistake rather always use protocol less URL for referencing
jQuery.
After this setup, you can use jQuery in your ASP.NET page. Let's see a demo.
Show alert window on click of ASP.NET Button.
Assuming a ASP.NET button with ID "btnSubmit " is placed on the page.
After this setup, you can use jQuery in your ASP.NET page. Let's see a demo.
Show alert window on click of ASP.NET Button.
Assuming a ASP.NET button with ID "btnSubmit " is placed on the page.
<asp:Button
ID="btnSubmit" runat="server" Text="Button" />
And now bind the
click event to ASP.NET Button in document.ready section.
<script
type="text/javascript">
$(document).ready(function() {
$("#btnSubmit").click(function()
{
alert("Alert using jQuery");
});
});
</script>
In above jQuery code
block, we have attached click event to the button using ID selectors. Read more
about other jQuery selectors and how to use them.
Below is a list of useful jQuery code example for ASP.NET controls that we use on daily basis. One thing, while creating object of any ASP.NET control, always use ClientID. As when Master pages are used then the ID of the ASP.NET controls is changed at run time. Read more here. But with ASP.NET 4.0, this is changed and now you have control over the Client ID using ClientIDMode property.
Get label value:
Below is a list of useful jQuery code example for ASP.NET controls that we use on daily basis. One thing, while creating object of any ASP.NET control, always use ClientID. As when Master pages are used then the ID of the ASP.NET controls is changed at run time. Read more here. But with ASP.NET 4.0, this is changed and now you have control over the Client ID using ClientIDMode property.
Get label value:
$('#<%=Label1.ClientID%>').text();
Set label value:
$('#<%=Label1.ClientID%>').text("New
Value");
Get Textbox value:
$('#<%=TextBox1.ClientID%>').val();
Set Textbox value:
$('#<%=TextBox1.ClientID%>').val("New
Value");
Get Dropdown value:
$('#<%=DropDownList1.ClientID%>').val();
Set Dropdown value:
$('#<%=DropDownList1.ClientID%>').val("New
Value");
Get text of selected
item in dropdown:
$('#<%=DropDownList1.ClientID%>
option:selected').text();
Get Checkbox Status:
$('#<%=CheckBox1.ClientID%>').attr('checked');
Check the Checkbox:
$('#<%=CheckBox1.ClientID%>').attr('checked',true);
Uncheck the Checkbox:
$('#<%=CheckBox1.ClientID%>').attr('checked',false);
Get Radiobutton
Status:
$('#<%=RadioButton1.ClientID%>').attr('checked');
Check the
RadioButton:
$('#<%=RadioButton1.ClientID%>').attr('checked',true);
Uncheck the
RadioButton:
$('#<%=RadioButton1.ClientID%>').attr('checked',false);
Disable any control:
$('#<%=TextBox1.ClientID%>').attr('disabled',
true);
Enable any control:
$('#<%=TextBox1.ClientID%>').attr('disabled',
false);
Make textbox read only:
$('#<%=TextBox1.ClientID%>').attr('readonly',
'readonly');
What is the significance of the
Strong Name tool?
The Strong Name utility (sn.exe)
helps in creating unique public-private key pair files that are called strong
name files and signing assemblies with them. It also allows key management,
signature generation, and signature verification.
14. How can different versions of private assemblies be used
in the same application without a re-build?
You can use different versions of
private assemblies in the same application without a re-build by specifying the
assembly version in the AssemblyInfo.cs or AssemblyInfo.vb file.
15. What is Global Assembly Cache (GAC)?
GAC is a central repository (cache)
in a system in which assemblies are registered to share among various
applications that execute on local or remote machines. .NET Framework provides
the GAC tool (gacutil.exe utility), which is used to view and change the
content of GAC of a system. Adding new assemblies to GAC and removing
assemblies from GAC are some of the tasks that can be performed by using the gacutil.exe
utility. GAC can contain multiple versions of the same .NET assembly. CLR
checks GAC for a requested assembly before using information of configuration
files.
The gacutil.exe /i <assembly name> - is the command that is used to install an assembly in GAC. Users use the Command Prompt of Visual Studio to install an assembly in GAC by using this command.
You can see all the assemblies installed in the GAC using the GAC viewer, which is located at the <WinDrive>:<WinDir>\assembly directory, where <WinDir> is windows in Windows XP or windows in Windows Vista or WinNT in Windows 2000. Apart from the list of assemblies, the assembly viewer also shows relevant information, such as the global assembly name, version, culture, and the public key token.
The gacutil.exe /i <assembly name> - is the command that is used to install an assembly in GAC. Users use the Command Prompt of Visual Studio to install an assembly in GAC by using this command.
You can see all the assemblies installed in the GAC using the GAC viewer, which is located at the <WinDrive>:<WinDir>\assembly directory, where <WinDir> is windows in Windows XP or windows in Windows Vista or WinNT in Windows 2000. Apart from the list of assemblies, the assembly viewer also shows relevant information, such as the global assembly name, version, culture, and the public key token.
16. Where is the information
regarding the version of the assembly stored?
Information for the version of
assembly is stored inside the assembly manifest.
17. Discuss the concept of strong
names.
Whenever, an assembly is deployed in
GAC to make it shared, a strong name needs to be assigned to it for its unique
identification. A strong name contains an assembly's complete identity - the
assembly name, version number, and culture information of an assembly. A public
key and a digital signature, generated over the assembly, are also contained in
a strong name. A strong name makes an assembly identical in GAC.
18. What is the difference between
.EXE and .DLL files?
EXE
- It is an executable file, which can be run independently.
- EXE is an out-process component, which means that it runs in a separate process.
- It cannot be reused in an application.
- It has a main function.
DLL
- It is Dynamic Link Library that is used as a part of EXE or other DLLs. It cannot be run independently.
- It runs in the application process memory, so it is called as in-process component.
- It can be reused in an application.
- It does not have a main function.
PDB
is an abbreviation for Program Data Base. As the name
suggests, it is a repository (persistant storage as databases) to maintain
information required to run your program in debug mode. It contains many
important relevant information required while debugging your code; for e.g. at
what points you have inserted break points where you expect the debugger to
break in Visual Studio.
This
is the reason why many times Visual Studio fails to hit the break points if you
remove the *.pdb files from your debug folders. Visual Studio debugger is also
able to tell you the precise line number of code file at which an exception
occurred in a stack trace with the help of *.pdb files. So effectively pdb
files are really a boon to developers while debugging a program.
In SQL Server, there is a cool functionality by
which you can get the modified data as a result set.
Suppose there is a table containing rating information about any post and we want to get user's previous rating before updating the current / new rating. Then we might write our query like -
SELECT
[RATING] AS [OLD_RATING] FROM [M_RATINGS] WHERE [POST_ID] = 5 AND [USER_ID] = 316;
UPDATE
[M_RATINGS] SET [RATING] = 5 WHERE [POST_ID] = 5 AND [USER_ID] = 316;
Here the first SELECT query will give us the
previous rating (old rating) and after that in the second query it will
modify the rating with the new rating.
But the disadvantage is that in this approach we are making two database operations, i.e one SELECT and one UPDATE operation. Then a question may come to our mind- "Can't we do this by using a single Query?" Yes, there is a better approach which is provided by SQL Server, to get modified data after modification. We can use the following query instead of the above two -
UPDATE
[M_RATINGS] SET [RATING] = 5 OUTPUT DELETED.[RATING] AS [OLD_RATING], INSERTED.[RATING] AS [NEW_RATING] WHERE [POST_ID] = 5 AND [USER_ID] = 316; If the previous rating is 'X' then the above query will return
" While inserting or deleting data SQL Server maintains
some virtual tables. The Deleted virtual table stores the old data and the
Inserted virtual table stored the newly inserted or updated data. " The
OUTPUT clause can access the Inserted and Deleted virtual tables to select
the data to be returned. The OUTPUT clause can select all the columns from
these tables, or specify individual columns. In this example the Deleted
virtual table is being used to grab the original value, while the Inserted
virtual table stores the newly updated value. Not only in UPDATE statement we
can use it in INSERT & DELETE statements also.
|
||||
Use in INSERT Statement:
----------------------------------- The insert command makes the inserted virtual table available. INSERT [USER_DETAILS] ( [NAME], [ADDRESS], [COMPANY] ) OUTPUT INSERTED.[NAME], INSERTED.[ADDRESS], INSERTED.[COMPANY] -- We can also use INSERTED.* in this case VALUES ('Deviprasad Das', 'Bhubaneswar', 'Mindfire Solutions');
Use in DELETE Statement:
----------------------------------- When deleting data, only the deleted table will have any useful data to return. DELETE [USER_DETAILS] OUTPUT DELETED.[NAME] WHERE [ADDRESS] = 'Bhubaneswar'; |
No comments:
Post a Comment