C# Interview Questions Part 3

What is Parsing? How to Parse a Date Time String?

Parsing converts a string into another data type.

For Example:

string text = “500”;
int num = int.Parse(text);
500 is an integer. So, the Parse method converts the string 500 into its own base type, i.e int.

Follow the same method to convert a Date Time string.
string dateTime = “Jan 1, 2018”;
Date Time parsedValue = DateTime.Parse(dateTime);

What are Events?

Events are user actions that generate notifications to the application to which it must respond. The user actions can be mouse movements, keypress and so on.

Programmatically, a class that raises an event is called a publisher and a class which responds/receives the event is called a subscriber. Event should have at least one subscriber else that event is never raised.

Delegates are used to declare Events.

Public delegate void PrintNumbers();

Event PrintNumbers myEvent;

What are the different types of Delegates?

Different types of Delegates are:

Single Delegate: A delegate that can call a single method.
Multicast Delegate: A delegate that can call multiple methods. + and – operators are used to subscribe and unsubscribe respectively.
Generic Delegate: It does not require an instance of the delegate to be defined. It is of three types, Action, Funcs and Predicate.
Action– In the above example of delegates and events, we can replace the definition of delegate and event using Action keyword. The Action delegate defines a method that can be called on arguments but does not return a result. Action implicitly refers to a delegate.
Public delegate void TestInfo();
Public event TestInfo deathDate;
//Replacing with Action//
Public event Action TestDate;

Func– A Func delegate defines a method that can be called on arguments and returns a result.
Func my Del is same as delegate bool my Del(int a, string b);

Predicate– Defines a method that can be called on arguments and always returns the bool.
Predicate my Del is same as delegate bool my Del(string s);

C# Interview Questions

Difference between abstract and interface?

Abstract class: Abstract class provides a set of rules to implement next class. These rules will be provided through abstract methods.
Abstract method doesn’t contain any definition while inheriting abstract class all abstract methods must be override. If a class contain at least one abstract method then it must be declared as an abstract class.
Abstract classes cannot be instantiated(i,e., we cannot create object), but a reference can be created.
Abstract classes are also called as partial abstract class. Partial abstract classes may contain function with body and function without body. If a class contain all function without body the it is called as fully abstract class.
Interface: if a class contain all abstract method then that class is known as interface.
Interface supports multiple inheritance. In interface all methods are public abstract by default. Interface implementable. Interface can be instantiated, but a reference cannot be created.

Difference between array list and hash table?

Hash table stores data as name, value pair. While in array only value is stored. To access value from hash table, you need to pass name, while in array you need to pass index number.
We can store different type of data in hash table say “Int” or “String” while in array you can store only similar type of data.

What is List, Array List, Dictionary, Hash table, Stack, Queues?

List: list allow duplicate items, it can be accessed by index and support linear traversal
Array list: An array based list that doesn’t support generic types. It doesn’t support type safety and should be avoided.
Hash table: store data as name, value pair It is a basic key value pair that functions like an independent list
Dictionary: A Dictionary is more like Hash table that supports generic type and enforces type safety.
Queues: Queues control how items in a list are accessed. We typically either push or pop records from a queue in a particular direction (either the front or back). Not used for random access in middle.
Stack:(LIFO) where push/pop record on top of each other
Queues:(FIFO) where push record from top and bottom.

Advance C# Interview Questions

Difference between string and string builder?

The main difference is system string is immutable whereas system string builder is mutable.
Append keyword is used in string builder but not in system string. Immutable mean once we create we cannot modify it. Suppose if we want to give any new value to old value and and it will create new instance in memory to hold the new value.

Difference between application object and session object?

The session object is used to maintain the session of each user. If one user enter in to the application then they get session id if he leaves the application then session id is deleted. If they again enter in to the application then they get a different session id.
But for the application object the id is maintained for whole application.
Application object is same for all users (independent of users).
For each users session object is different.

Difference between scope-identity and current-identity?

Scope-identity and current-identity both are similar and it will return the last identity value generated in table
scope-identity will return the identity value in table i,e currently in scope.

C# Interview Questions

Difference between boxing and unboxing?

Boxing is a process of converting value type into reference type.
Unboxing is a process of converting referance type to value type.
eg:int stackvar=12
//int (value type) is created on stack.
object boxedvar=stackvar;
//boxing=int is created on the heap(reference type)
int unboxed=(int)boxedvar;
//unboxing=boxed int is unboxed from the heap and assigned to an int stock variable.
Value type:value type contain value directly.Memory is allocated in stock eg:any value type
Reference type:Reference type doesn’t contain value directly.Memory is allocated in heap. eg:any object type.

Difference between Get and Post method in Asp.net?

Get and Post methods are used for request between a client and server.
Get :request data from a specified resource.
Post: submits data to be processed to a specified resource.

*Data is appended to URL.*Data is not appended to URL.
*Data is not secret.*Data is secret.
*It is single call system.*It is a two call system.
*Max data that can be sent in 256.*There is no limit on amount of data.
*Data transmission is faster.*Data transmission is comparitively slow.
*This is the default method for many browsers.*No default and should be explicitly specified.

Difference between Grid view and Data grid?

*It was introduced with Asp.net 2.0.*It was introduced with Asp.net 1.0.
*Built in support for paging and sorting.*For sorting you need to handle sort command event and for paging you need to hand page inde changed event.
*Built in support for update and delete operations.*Need to write code for implemating update and delete operations.
*Supports autoformat or style features.*This feature is not supported.
*performance is slow compared to Data grid.*Performance is fast as compared to Grideview.

Advance C# Interview Questions

What is Http handler?

“Http handler is the low level request and response API to service incoming Http request
In simple, an Asp.NET Http handler is a class that implement the system. Web http handler interface.
Asp.NET Http handler are responsible for intercepting request made to you Asp.NET web application server. They run as process in response to a request made to the Asp.NET site.
The most common handler is an Asp.NET page handler that process aspx files.
When user request an aspx file, the request is processed by the page through page handler.
Asp.NET offers a few default Http handler

  • Page handler(aspx): Handles web page
  • User control handler(.ascx):handler web user control page
  • Web service handler(.asmx):handler web service page.
    WE can create our own custom Http handlers that render custom output to the browser.
    Typical scenarious of Http handler in Asp.NET are example.
    Delivery of dynamically create image(charts for example) or resized pictures.
    Rss feeds which emit Rss formated XML.
    We implement the IHttp handler interface to crate a synchronous handler and the IHttpASync handler interface to creat an asynchronous handler.The interface require us to implement the process request method and the IsREusable Property.
    The process request method handles the actual processing for request made, while the boolean Is Reusable property specifies wheather your handles can be pooled for handles is required for each request.”

Type of memories in .net?

Two type of memories are there in .net. (1)stack memory (2)heap memory

Stack is used for static memory allocation.Heap is used for dynamic memory allocation.
variables allocated on the stack are stored directly to memory.
and access to this memory is fast. eg:stack int x=1,int y=2.
Variable allocated on the heap have their memory allocated at run time and accessing this memory is a bit slower. eg: Heap from object.

Difference between Abstract and Interface?

Abstract cannot be instantiated but we can inherit.Interface cannot be inherited but can be instantiated.
Abstract contains both declarations and definition.Interface contain only declarations.
A class which contain abstract method is abstract class.Class which contain only abstract method is interface class.
In abstract we have a chance of declaring any access specifies.By default public is access specifice for interface.We don’t have chance to deelae other specifies.

NOTE: Abstract class has some default properties.

  • It cannot be private (by default its publice).
  • It cannot be static.
  • It cannot be sealed ( it has to be inherited).
  • Abstract methods cannot be used with virtual keyword. By default they are virtual and used to be overridden in child classes.

C# Interview Questions

Program to find the length of string ?

For(int i=0;str[i]="\n";i++)

How to choose between web API and WCF?

“Choose Web API when you want to creat the service that user all http feature,suchas request and response heades,URIs etc.
If you want to expose broad range of client like mobile,iphone and browser.
WCF:When you want to creat secure that support one way messaging,messaging communication.
For fast transport channel,such as TCP,UDP,named pipe etc.”

Difference between list view and grid view?

Introduced with 3.5.Introduced with 2.0.
Template driven.Rendered as table.
Built in support for data grouping.
Built in support for insert operation.
Provides flexible layout.
Fast compared to gride view.Slow performance compared to list view.

Advance C# Interview Questions

Difference between constants and read only and ?

Constants: The value can’t be changed
Read only: The value will be initialized only once from the constructor of class.
Static: Value can be initialized once.

Constant field must be assigned a value at the
time of declaration and after that they cannot be modified.
eg:public const int x=10;
Readonly field can be initialized at the time
of declaration or with in the constructor of same class.
eg:public const int x=10; eg:readonly int x=10;

When to use API?

“When you want to expose data to multiple clients.
It uses web standards such as HHP,JSON and XML and it provides simple way to build and expose rest based data services.”

Why API?

“It is an ideal platform for building result full application on .NET frame work.
1.To accept intercut from browse, mobiles.
2.To provide data to apps.”

C# Interview Questions

What is Rezor type?


  • EmptyResult
  • FileResult
  • JavascriptResult
  • JsonResult
  • RedirectResult(Redieel to another action method using its URL).”

What is restful web service?


Webservice: SOAP

Uses of global.asax?

Global.asax is basically Asp.net application file.Its a place to write code for application level events such as application start,application end,session start and end,application error etc.Raised by asp.net or by HHP modeles.

  • Application-Init—->Occure in case of appy initialization for very first time.
  • Application-start—>Fires on application start.
  • Session-start—>When a new user session start.
  • Application-error—>When unhandled exception.
  • Session-end—>Fire when session ends.
  • Application -end—>Fires to application ends or timeout.

Advance C# Interview Questions

Relationship between a class and an object?

A class acts as a blue-print that defines the properties, state, and behaviours that are common to a no of object.
An object is an instance of the class for eg: Vehicle is class. Car is an object.
An class can have multiple object eg: van, truck and auto.
The new operator is used to create an object of class. when an object if a class is instantiated, the system allocated memory for every data member that is present in the class.

Basic feature of OOPs?

The following are the four basic feature of OOPs.

  • ABSTRACTION: Refers to the process of exposing only the relevant and essential data to the user without showing unnecessary information.
  • POLYMORPHISM: Allows you to use an entity in multiple forms.
  • ENCAPSULATION: Prevents the data from unwanted access by binding of code and data in a single unit called object.
  • INHERITANCE: Promotes the reusability of code and eliminates the use of redundant code. It is the property through which a child class obtain all the feature defined in its parent class.
    The class inheriting the properties is called derived class and the class that allows inheritance of its common properties is called base class

Collection and Generics?

A collection can be defined as a group of related items that can be referred to as a single unit.
The system collection name space provides you with many class and interface. Some of them are array list, list, stack, I collection, ienumerable and I dictionary.
Generics provide the type safety to your clap at compile time. While creating a data structure, you never need to specify the data type at the time of declaration.
The system ,collection generic name space contain all the generic collection.

C# Interview Questions

What is enumeration?

Enumeration is defined as a value type that consist of a set of named value.These values are constants and are called enumerators.
An enumeration type is delared using the enum keyboard. Each enumerator is an enumeration is associated with an underlying type that is set by default on the enumarator.

When do you really need to create an abstract class?

We define abstract classes when we define a template that needs to be followed by all the derived classes.
All the abstract methods in an abstract class need to be overridden compulsorily
eg: abstract class base

        public void method1()
           //some code.
       public abstract void method2();//must be override
       public void method3()
           //some code 
        class derived:base
     Now only method2 need to be overidden as it is abstract class.

What is business logic?

It is a functionality (code) which handle the exchange of information between data base and a interface.

Advance C# Interview Questions

What is components?

A component is a group of logically related classes and methods.
A component is a class that implements the I component interface or user a class that implements I component interface.

Difference between REST and SOAP?

Exposes resources which represent data.Expose operation which represent logic.
User HHP verbs (get/post/delete/put).User HHP post.
Support multiple data formats.Supports only XML

What is Globalization?

Globalization is the process of customizing application that support multiple cultures and region.

C# Interview Questions

What is localization?

Localization is the process of customizing application that support a given culture and region.

What is assembly main fest?

Part of assembly which contains assembly meta data that describes the assembly itself is known as manifest.
Assembly manifest contain assembly name, version number, culture, strong name, list of files inside the assembly and reference information.

What is base action filter attribute class?

“This class is used to implement a custom action filter easily.
It Implement both I action filter and I result filter interface and inherited from filter class.
Action filter attribute class has following method which can be overridden
OnActionexecuting—>Before controller action
OnActionexecuted—>After controller action
OnResultexecuting–>Before controller action Result
OnResultexceuted–>After controller action”

Advance C# Interview Questions

Difference between Dataset and Data Reader?

Data reader is like a forward only recorset. It fetches one row at a time so very less network cost compared to dataset.Dataset is an in memory representation of a collection of database object including tables of a relational DBschemas.
Data Reader is read on lt so we can’t do any transaction on them.Data is always a bulky object that requires a lot of memory space.
Data Reader is best choice where we need to shown data to user.Dataset is a small database because it store the schemas and data in apple memory user.

What is custom tag?

Custom tag allows you to create your own tag and specity value for it.

What is SOAP?

Soap is a protocol for sending and receiving data over HHP as XML.

C# Interview Questions

Difference between var, object and dynamic types?

VAR: Var is a keyword introduced with .NET 3.5 and used to store any kind of data like dataset, data table, int , float, char etc. We can keep any kind of data.
eg: Var my var =new string []{“hellow”,”world”}; Above my var is var type used to store the string array.
OBJECT: Object is the type which is used to store the object of any kind. These object need to be type caste when required.
eg: Object my obj=”HELLOW”
Now when we want this variable value we need to type cast it as string str=(string)my obj;
DYNAMIC: Dynamic is a keyword introduced with .NET and 4.0 and used to keep the data similar to var keyword. The difference between var and dynamic is that the dynamic variables user the same memory location to store the object and not change through out the application.

C# Part 1C# Part 2
Back to top