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;

Thursday, 8 October 2015

Service Bus

A service namespace provides a scoping container for addressing Service bus resources within your
application.

1.it is useful to communicate decoupled applications

Note :Microsoft azure service bus install from nugetpackage

namespace : microsoft.ServiceBus

NamespaceManager class can be used to manage messaging entities in the service bus.

creation of queue :
===================
String strcon = ConfigurationManager.Appsettings["Microsoft.ServiceBus.ConnectionString"].tostring();

NamespaceManager nsMgr=NamespaceManager.CreateFromConnectionString(strcon);

if(nsMgr.QueueExists("TestQueue123"))
{
 nsMgr.DeleteQueue("TestQueue123");
}
else
{
 nsMgr.CreateQueue("TestQueue123");
}
add message to queue  and send:
==================
String strcon = ConfigurationManager.Appsettings["Microsoft.ServiceBus.ConnectionString"].tostring();

QueueClient qclint=QueueClient.CreateFromConnectionString(strcon,"TestQueue123");
BrokeredMessage message=new BorkeredMessage("My message to queue123");
qclient.send(message);

Receive Message :
================
BrokeredMessage message=null;
String strcon = ConfigurationManager.Appsettings["Microsoft.ServiceBus.ConnectionString"].tostring();

QueueClient qclint = QueueClient.CreateFromConnectionString(strcon,"TestQueue123");
 message= qclint.Receive(TimeSpan.FromSeconds(5));
if(message!=null)
{
message.complete();
}

qclient.close();


Wednesday, 7 October 2015

dot net questions


1.what is an assembly ?

A precompiled code that can be executed by the .net runtime environment.
it can  be an .exe or dll.
A .net program consist of one or more assemblies.

There are three types of assembiles.

1.public Assembly / Shared Assembly:

it is a dll which can be used by multiple applications at a time.A shared assembly is stored in GAC i.e. Global Assembly Cache.

2.Private Assembly :

The dll or exe which is used by only one application  and generally stored in the Application specific floder.

3.Satellite Assembly :

A Satellite assembly contains only static objects such as images and other non-executable files such as resource - only files that are required  by the application.

2.What is the prerequisite to delpoy an  assembly in GAC?

The assembly must be strong named.A 'Strongly named' assembly is an assembly that is signed with a key to ensure its uniqueness.


3.What is strong Name?

A strong name is a combination of it's name,version number,culture information,public key and a digital signature.this ensure that the dll is unique.

Strong names provides an integrity check that ensures that the contents of the assembly have
not been changed since it was built.

4.What are generics ? how do you increase performance using generics ?

Generics allows you to define type-safe data structures,without specifying the actual data
types.This increases the performance of the code and code resuse. Thus generics allows you
to write a class or method that can work with any datatype.since generics is type safe it
avoids boxing and unboxing which increases the performance of the code because you no need
convert an object to specific datatype and vicevera.

Have you heared about IComparable? How does it works?

A class can implement IComparable interface if you want to compare the objects of that class.then in that class we have to implement the 'CompareTo' method and provide the implementation to compare two class objects.

What is managed code ?

Managed code is the code whose execution is managed by the .net framework common language
runtime(CLR).The CLR ensures managed execution environment that ensures type safety,exception
handling,garbage collection and array bound & index checking.

What is unmanaged code ?

Application that do not run under the control of the CLR are said to be unmanaged. This is
the code that is directly executed by the operating system.

What is dispose and finalize ?

The Dispose method is generally called by the code that created your class so that we clean up and release any resources we have acquired(database connection/file handles) once the code is done with the object.The finalize method is called when the object is garbage collected and its not guaranteed when this will happen.

Difference between ReadOnly and Const?

1.A Const can be initialized only once whereas   ReadOnly can be initialized at runtime in
 the constructor.
2. Constants are static by default that is they  are compile time constants whereas Readonly are
  runtime constants.
3.Constants must a have at compilation-time and  they are copied into every assembly that uses them.
 Readonly instance fields must be set before the  constructor exits because they are evaluted
 when object is created.

What is the difference between abstract classes and interfaces?

Interface must have only methods without implementation whereas abstract classes can have methods with and without implementation that is you can define a behaviour in an abstract class.

An interface cannot contain access modifiers whereas an abstract class can contain access modifiers.

A class can implement multiple interfaces whereas a class can inherit only one abstract class.

An interface cannot have variables whereas  an abstract class can have variables and constants defined.

when we add a new method to an interface,we have to track all the classes which implement
this interface and add the functionality to this method whereas in case of abstract class we can
add default behavior for the newly added method and thus the class which inherit this class
works properly.

Interfaces are for when you want to say "I don't care how you do it, but here's what you need to get done"

Abstract classes are for when you want to say  "I know what you should do, and I know how you
 should do it in some/many of the cases."




Differnce Between ASMX webservice and wcf webservice ?

ASMX Webservice :
 1. it supports only http protocols
 2.it an be hosted in iis only

wcf Service :
 1. it supports HTTP (Rest and soap),tcp/ip,msmq   and many more portocols
2. it can be hosted in iis,self,windows service and windows   activation service(was).

Explain the different types of triggers in  SQL Server?
There are three types of tiggers :

1. DML Trigger
2.DDL Trigger
3.Logon Trigger

Instead of trigger are fired in place of the
triggering action such as insert,update,delete

After trigger execute following the
triggering action,such as an insert,update,or
delete.

1.DML Trigger :(Insert,Update,Delete)
  DML Triggers again divided into two types
 1.For Triggers\After Triggers
 2.Instead of triggers

2.DDL Triggers :(Create ,alter,drop)
   The DDl Triggers are always after triggers
3.logon triggers :
 This type of trigger is fired against a LOGON
event before a user session is established to
the sql server.


Jquery library comes in 2 different versions production and deployment.
The deployment version is also known as minified version.
So .min.js is basically the minified version of jquery library file.
Both the files are same as far as functionality is concerned.
But .min.js is quite small size so it loads
quickly and saves bandwidth.

1.The starting point of jquery code execution
is $(document).ready() function which is
executed when DOM is loaded.

2.The Same page can have any number of
  document.ready() function.

Monday, 24 August 2015

Difference Between var and dynamic in c#

var Keyword :
==================

1.Introduced with c# 3.0
2.It is type safe.Compiler knows the type of it at compile time
3. Intellisense is available
4.Useful when you don't know type of it.

Dynamic Keyword :
===================

1.Introduced with c# 4.0 on the top of dynamic language runtime.
2.It is not type safe,you will only get to know type of it at runtime.
3.Intellisense is not available.
4.Useful when you use things like office   interop or something return from the   dynamic language              like ironruby.

Sunday, 17 May 2015

Advantages of Asp.net MVC :



1.Provides clean separation of concerns(SOC).

2.Enables the full control over the rendered HTML.

3.Enables TEST DRIVEN DEVELOPMENT(TDD).

4.Easy Integration with javascript framework.

5.Following the design of stateless nature of the web.

6.RESTFULL urls that enables SEO.

7.No ViewState and postBack events.

Friday, 15 May 2015

Remove extra spaces at the end of column in sql server




Similarly we can remove the Line Feed and Carriage return. We assume that tab,
line feed and carriage returns are not acceptable characters anywhere in a string.
So we can finally create our whitespace removal function as:


CREATE FUNCTION DBO.TRIM(@STR NVARCHAR(MAX))

RETURNS NVARCHAR(MAX)

BEGIN

declare @TAB nvarchar(2), @LF nvarchar(2), @CR nvarchar(2),@NL varchar(2)

set @TAB = char(9)

set @LF = char(10)

set @CR = char(13)

set @NL = char(13)+char(10)

return replace(replace(replace(replace(LTRIM(RTRIM(@STR)), @TAB, “), @NL, “), @LF, “), @CR, “)

END

Thursday, 14 May 2015

Sub-Types of ActionResult in Asp.mvc4


ActionResult is an abstract class that can have several sub types.
 (or )
ActionResult is a general type that can have several subtypes .

ActionResult SubTypes :

1.ViewResult : Renders a specified    view to the response stream.

2.PartialViewResult : Renders a   Specified partial view to the   response stream.

3.EmptyResult : An empty Response is   returned.

4. RedirectResult : Performs an HTTP   redirection to a specified URL.

5.RedirectToRouteResult : Performs   an HTTP redirction to a URL that    is determined by the routing                                                   engine,based on given route data.

6.JsonResult : Serializes a given   ViewData object to JSON format.

8.JavascriptResult : Returns a piece  of javascript code that can be   executed on the Client

9.ContentResult : Writes content to   the response stream without    requrining a view .

10.FileContentResult : Returns a  File to the Client.

11.FileStreamResult : Returns a file to the client,which is provided by a stream.

12.FilePathResult : Returns a file to the Client.