Friday, 19 May 2017

ref vs out parameter in c#

ref tells the compiler that the object is initialized
before entering the function,while out tells
the compiler that the object will be initialized
inside the function.

ex: ref:
=========

public static void Main()
{
 int i = 3; // Variable need to be initialized
 sampleMethod(ref i );
}

public static void sampleMethod(ref int sampleData)
{
 sampleData++;
}

Note :
1.A ref variable needs to be initalized before
passing it in.
2.ref parameters can be thought of as both
input and outup variables.


ex: out :
===========

public static void Main()
{
 int i, j; // Variable need not be initialized
 sampleMethod(out i, out j);
}
public static int sampleMethod(out int sampleData1, out int sampleData2)
{
 sampleData1 = 10;
 sampleData2 = 20;
 return 0;

Saturday, 17 December 2016

Typeof() vs GetType()


 GetType():
====================
if you want to obtain the type from an instance of your class,you can use GetType().

GetType() returns run time type of the instance.

TypeOf():
===============
if you don't have an instance,but you know the type name,you would use typeof().

TypeOf() gives the compile time of class.

Note :
=====
Operator TypeOf(ClassName) is used to obtain the System.Type object for a Type at compile time.

MyObject.GetType() is used to obtain the exact run time type of object.This method uses reflection.

Finalize vs Dispose in C#

Finalize() is called by Garbage Collector to free unmanaged resources.The garbage collector calls this method at some point after there are no longer valid references to the object.

some resources like windows handles,database connections which cannot be collected by the
garbage collector.Therefore the programmer needs to call Dispose() method of IDisposable interface.

Dispose() of IDisposable interface is called by the programmer to explicitly release resources when they are no longer being used.Dispose() can be called even if other references to the object are alive.

Arguments vs Parameters in C#

Parameters :
==================
A parameter is a variable in
a method definition.

ex :
public void MyMethod(string my param)
{
// your coding
}


Arguments :
================
when a method is called,the arguments
are the data you pass into the method's
parameteres.

ex :
string myarg1="This is my argument";
myclass.MyMethod(myarg1);

Monday, 18 January 2016

Bundling and Minification in asp.net MVC

Bundling and Minification techniques reduce the number of request to the server and size of requested CSS and JavaScript library,which improve page loading time.

Bundling reduces the number of individual HTTP request to server by combining multiple CSS files and JavaScript files into single CSS file and JavaScript file.

Minification reduces the file download size of CSS and JavaScript files by removing white space,comments and other unnecessary characters.

Advantage of Bundling :
=====================
Bundling and Minification primarily improve the first page request load time.
Once a web page has been requested,the browser caches the assets(JavaScript ,CSS and images).
So bundling and Minification won't provide any performance boost when requesting the same
page,or pages on the same site requesting the same assets.

Note :
In debug mode bundling is switched off by default.To enable bundling in debug-mode

BundleTable.EnableOptimizations=true;

Sunday, 17 January 2016

NoLock & NoWait in sql server

NOWAIT will return error if the original table has (transaction) locked on it.

NOLOCK will read the data irrespective of the (transaction) lock on it.

Sunday, 29 November 2015

Anonymous Method And Lambda Expression


Anonymous Methods were introduced in c# 2.0 as a way of creating delegate instances without
having to write a separate method . They can capture local variables within the enclosing method making them a form of closure.

what is Anonymous method ?

Anonymous method is an inline un-named method in the code.

1.it is created using the delegate keyword and
doesn't require name and return type and hence we can consider an anonymous method has only body without name and return type.

syntax :
==========

 delegate ( [ argInfo ] )
{
// statements
}

What is lambda expression ?

A lambda expression is an anonymous function that we can use to create a delegate or expression tree types.

By using Lambda Expressions you can create local functions that can be passed as arguments or returned as the value of function calls.

Syntax :
==========

(input parameters) => expression;