Friday, March 31, 2017

How do you convert int to char in C#? Ex: print 1 as character on console

int x=4;
char c=(char)x;

it would not print '4' on screen. It would display the ASCII corresponding value of '4'.

I tried this way...
int x=48;
string str =x.ToString();
char c=str[0];//for printing 4;
char c1=str[1];// for printing 8;

Thursday, March 30, 2017

Explain connected and disconnected architecture in ADO.NET

The ADO.net architecture, in which connection must be kept open till the end to retrieve and access data from database is called as connected architecture. Connected architecture is built on the these types - connectioncommanddata reader
The ADO.net architecture, in which connection will be kept open only till the data retrieved from database, and later can be accessed even when connection to database is closed is called as disconnected architecture. Disconnected architecture of ADO.net is built on these types - connectiondata adaptercommand builder and dataset and data view.

Wednesday, March 29, 2017

Tell about abstract class

Abstract classes are defined as classes using the modifier "abstract". When we want a class to be base class and we don't want to instantiate we use abstract classes. Many a times abstract classes are either partially implemented or not at all implemented.

An abstract class can contain either abstract methods or non abstract methods. Abstract members do not have any implementation in the abstract class, but the same has to be provided in its derived class.

An abstract class cannot be sealed class. We can have abstract methods only in abstract classes. We should use same access modifier for an abstract method in both base class and derived class to avoid compilation errors.

An abstract method cannot have virtual as it is implicitly virtual.

Monday, March 27, 2017

What is index and what are the uses?

Indexes are used to retrieve data from the database very fast. The users cannot see the indexes, they are just used to speed up searches/queries.

Without an index when we run a select query on a Customer database with three columns customername, customerage and customerphonenumber with 1000  records to look for customer name "John”, the database software would literally look at each and every row of the database. Even if it finds "John" it would still look at remaining rows because there may be other customers too with same name.
So, to make this kind of searches fast we make of indexes. Indexing is a way of sorting several records on multiple fields. When we create an index on a field in a table it will create another data structure which holds the field value, and pointer to the record it relates to. This index structure is then sorted, allowing Binary Searches to be performed on it.

Explain about Triggers in SQL

database trigger is procedural code that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database.

The database trigger are executed either before or after our required code. By default it is executed after.

Example:CREATE [OR REPLACE ] TRIGGER trigger_name  
{BEFORE |AFTER |INSTEAD OF}
{INSERT [OR] | UPDATE [OR] |DELETE}
[OF col_name]
on table_name

Sunday, March 26, 2017

What do you mean by endpoints in WCF?

All communication with a Windows Communication Foundation (WCF) service occurs through the endpoints of the service. Endpoints provide clients access to the functionality offered by a WCF service. We expose endpoints for making our service to be consumed.
Each endpoint consists of four properties:
  • Address: The address uniquely identifies the endpoint and tells potential consumers of the service where it is located. We mainly use URL as address.
  • Binding: The binding specifies how to communicate with the endpoint like transport protocol, encoding for messages and necessary security requirements. WCF uses by default wsHttp binding. 
  • Contracts: The contract outlines what functionality the endpoint exposes to the client.There are many contracts like service, operation, data, fault and message contracts. A contract specifies:
    • What operations can be called by a client.
    • The form of the message.
    • The type of input parameters or data required to call the operation.
    • What type of processing or response message the client can expect.
  • Behaviors: We can use endpoint behaviors to customize the local behavior of the service endpoint. Endpoint behaviors achieve this by participating in the process of building a WCFruntime.

Saturday, March 25, 2017

Explain Events

Events enable a class or object to notify other classes or objects when something of interest occurs. The class that sends (or raises) the event is called the publisher and the classes that receive (or handle) the event are called subscribers.

Events use delegates and limit communication to only one way. The subscribers only can listen and cannot modify the publisher.

Explain Delegates

A delegate is a type safe function pointer, it holds a reference to a function. The signature of the delegate must match the signature of the function, the delegate points to. A delegate is similar to a class and we can create an instance of it. Delegates are mainly used for communication and callbacks.
Delegates provide two way communication.

We can use multi cast delegates when we need to reference more than one function. When we invoke a multi-cast delegate, all the functions the delegate is pointing to, are invoked.

Friday, March 24, 2017

What is DataReader in ADO.NET?

DataReader is a connected, read-only and forward dataset. We cannot write to database using datareader. It helps to sort,search and filter dataset.

Thursday, March 23, 2017

What is connection pooling in ADO.NET

When we create a connection to a database it is time consuming as it involves network-level handshaking and security credentialing for every new connection. In ADO.NET we use connection pooling, which reduces the cost of repeatedly opening and closing connections. In connection pooling the object we created for connection is sent to a pool rather than to a garbage collector and whenever we use the same connection string, it uses the object from pool instead of creating a new connection. There will be individual pools for each connection string and with same connection string we can have many connection objects.

By default pooling is enabled and we can turn off pooling for a specific connection by including the Pooling=false key-value pair in our connection string.

Wednesday, March 22, 2017

Explain about generics?

Generics are introduced in C# 2.0, they allow us to design classes and methods decoupled from data types. We can make use of generics and increase code reuse, type safety and performance.

Tuesday, March 21, 2017

What is a constructor and types of constructors?

When we create a class or struct, its constructor is called. Constructor will have same name as a class or struct and is usually used to initialize the data members of the new object. There are three types of constructors:

Instance constructors are used to create and initialize any instance member variables when we use new expression to create an object of a class.

Static constructors are used to initialize static data or to perform actions that need to be performed only once. It is called automatically before first instance is created or any of the static members are referenced.

Private constructors are only used when a class contains only static members.

How does Garbage collector work ?

Garbage collector serves as a automatic memory manager. It allocates memory for objects on managed heap. The heap is divided into three generations, generation 0, generation 1 and generation 2 , so it can handle short-lived and long-lived objects. A temporary variable is an example of short-lived object and an object in server application with static data is an example of long lived object.

Generation 0 is youngest generation and contains short-lived objects. All newly created objects are contained in generation 0. Garbage collection occurs more frequently in this generation. If there is no memory in generation 0, they are promoted to generation 1.

Generation 1 acts as a buffer between short-lived and long-lived objects, it contains short-lived objects.

Generation 2 contains long lived objects.

A garbage collection has the following phases:
  • A marking phase will find and create a list of all live objects.
  • A relocating phase will update the references to the objects that will be compacted.
  • A compacting phase will reclaim the space occupied by the dead objects and will compact the surviving objects. The compacting phase will move objects that have survived a garbage collection toward the older end of the segment.
Collecting a generation means collecting objects in that generation and all its younger generations.

What is managed code and unmanaged code?

Managed code is not compiled to machine code but to an intermediate language which is interpreted and executed by some service(Common Language Runtime in case of .NET) on a machine and is therefore operating within a secure framework which handles dangerous things like memory and threads for us.

Unmanaged code is compiled to machine code and therefore executed by the Operating System directly.

Monday, March 20, 2017

What is Common Table Expression in MS SQL Server?

We can think of common table expression as a temporary result set that is defined within the execution scope of a single SELECT, INSERT, UPDATE, DELETE, or CREATE VIEW statement. It lasts only for the duration of the query and can be referenced multiple times in the same query.

What is linked server?

Linked Servers allows us to connect to other database instances on the same server or on another machine or remote servers. It allows SQL Server to execute SQL scripts against OLE DB data sources on remote servers using OLE DB providers. 
After setting up the Linked Servers we can easily access the other server tables, procedures etc. 

Once the connection is established, we can start with the CRUD operations. The advantage is about security; its works on Windows as well as SQL Server Authentications. 
In Sql Server we refer as linked servers and in Oracle we refer them as database links.

Sunday, March 19, 2017

What is use of temp data?

Temp data in MVC is used to store temporary data which can be used in subsequent request. Temp data is cleared out once it is read in any other request. To preserve the Temp data for subsequent requests we can use of  TempData.Keep().

What is stored procedure

A stored procedure is a set of Structured Query Language (SQL) statements with an assigned name, which are stored in database as a group, so it can be used and shared by multiple programs any number of times.

Saturday, March 18, 2017

what is the difference between web service and a web application?

Web Application:Any application which we can run in our web browser is a web application.

Web Service:A web service is an Application Program Interface (API) that runs on the server, which provide data to the client over http through a standardized messaging system. (XML, JSON, etc...). 

Thursday, March 16, 2017

What is the difference between Var and Dynamic in C#?

"Var" is statistically typed,this means type of variable declared is decided by compiler at compile time.This type of variables should be initialized at the time of declaration.

"Dynamic" is dynamically typed ,this means the type of variable declared is decided by compiler at run time.This type of  variables are need not be initialized.

Wednesday, March 15, 2017

difference between ToString() and Convert.ToString()?

ToString() will throw exception for null values,Convert.ToString() will not throw any exception for null values.

Tuesday, March 14, 2017

difference between varchar and nvarchar

Nvarchar stores UNICODE data. If you have requirements to store UNICODE or multilingual data, nvarchar is the choice. Varchar stores ASCII data and should be your data type of choice for normal use.

Monday, March 13, 2017

How do you create a proxy using svcutil?


  1. Open visual studio developer command prompt.
  2. Start your service and make sure it is up and running.
  3. Copy the URL of service .
  4. In visual studio command prompt type " svcutil [URL] /out:filename.cs /config:filename.config

This will generate two files in the local as mentioned above in the command prompt.

Saturday, March 11, 2017

What is the difference between Compile time Exception and Runtime Exception?

Compile time is where your compiler transforms your source code to a machine understandable language.
During the compile time, it processes through various stages:
Creation of Symbol table, Syntax analysis, Semantic analysis, Code optimization, Code Generation & Error Handling.
Runtime is during the execution process(Eg: Page request is made. or looping through a variable instances, etc). Runtime errors are handles after the successful compilation.

Can abstract class be Sealed in C#?

An abstract class cannot be a sealed class because the sealed modifier prevents a class from being inherited and the abstract modifier requires a class to be inherited.

Friday, March 10, 2017

Best C# Practices to follow


  1. Always name things well.
  2. Make sure there is only one class per file.
  3. Always try to use properties instead of public variables.
  4. Write methods to make only one thing.
  5. Use public modifier only when necessary.
  6. Try to keep everything simple.
  7. Always be consistent.
  8. Use curly braces for if statement.
  9. Concatenate strings using "$".
  10. Avoid global variables.(Make use of app.config file to declare global variables if needed).

Thursday, March 9, 2017

How to revert a check in made in Team Foundation Server ?

Go to Team Explorer and in source control explorer select your project.

Right click and select view history.

In history click on the change set , you want to cancel.

Right click on the change set and select rollback entire change set.

Wednesday, March 8, 2017

What is a "Table", "Record", "Field" ?

A table is a collection of records of specific type.
Ex:Employee Table, Salary Table.

A record is a collection of values/specific entity.
Ex:Employee, Salary.

A field is an area within a record for a specific piece of data.
Ex:Employee Name, Employee Id.

What is a foreign key?

When a 'one' table's primary key field is added to a related "many" table in order to create a common field which relates the two tables , it is called foreign key in the "many"  table.

What is a primary key?

A primary key is a column whose values uniquely identify every row in a table. It should be unique and not null.

How to reset column identity in SQL server?

Sometimes we delete rows from a table and the identity will not start as expected from one, it would assign a random value. In order to reset the value we have to use the following command.

DBCC CHECKIDENT ('[TableName]', RESEED, 0);
GO

Tuesday, March 7, 2017

What is Lazy Loading?

Lazy loading loads data into cache only when necessary. Write through adds data or updates data in the cache whenever data is written to the database.Lazy loading allows for stale data ,but wont fail with empty nodes and may populate the cache with superfluous data, a problem referred to as "cache churn" .

          Adding a time to live (TTL) value to each write allows us to enjoy the advantages of each strategy and avoid cluttering up the cache with superfluous data. Unrelated to these issues is consistent hashing, which is technique used to partition data keys between nodes in cluster.
 

Tell about static and instance class members?


  • When a class member includes a static modifier,the member is called as static member.When no static modifier is present the member is called non-static or instance member.
  • Static members are invoked using class name where as instance members are invoked using instances(objects) of the class.
  • An instance member belongs to specific instance(object) of a class.If we create three objects of a class we have three sets of instance members in the memory, where as there will ever be only one copy of the static member,no matter how many instances of a class are created.

Monday, March 6, 2017

What is GAC? Where is it located?

Global assembly cache  (GAC) is a folder in windows directory to store the .NET assemblies that are specifically designated to be shared by all applications executed on a system. Assemblies can be shared among multiple applications on the machine by registering them in global assembly cache(GAC).

To install assembly in Cache, use  Gacutil. To run Gacutil, goto "Visual Studio Command Prompt" and type "gacutil -i <assembly_name>", where (assembly_name) is the DLL name of the project.

 To uninstall assembly, type gacutil –u <assembly name> in  Visual Studio Command Prompt.

What is Assembly?

An Assembly is a "unit of deployment" for .NET ,almost always a .exe or .dll. A .NET assembly is a file that contains our compiled code, code that can execute under supervision of Common Language Runtime.

In C# terms its basically a single C# project.

Assemblies are building blocks of  .NET Framework applications; they form the fundamental unit of deployment ,version control, reuse ,activation, scoping and security permissions.

An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of the type implementations. To the runtime, a type does not exist outside the context of an assembly.

Sunday, March 5, 2017

What is a Object?

An object is an entity that has Properties for identifying State, Methods for behavior, Events for depicting the change of State.

Data associated at any given instance of time is the state of an object.

Every object differs from other objects either by state or behavior.

Saturday, March 4, 2017

Using Column Names "FROM" and "TO" in a table and trying to lnsert data into table

When in a database if you have a table with column names "FROM" and "TO" you should be careful while trying to reference these column names in your sql command.

You should enclose these column names in square  brackets so that SQL will identify them as column names and our command works as we expected without any errors.

You should enclose as shown here:

Select CompanyName,[From],[To],Skillset from WorkExperience 

Friday, March 3, 2017

What is CLR

Common Language Runtime or CLR is the run-time execution environment of .Net Framework. Converting MS-IL into platform or OS specific code is done by the CLR.
CLR is responsible for bringing application to life and its also the CLR’s job to tear down application when its finished executing or if it has an unrecoverable error.

CLR actively tracks all the memory a program uses and it knows when the program is finished with memory so it will clean things up and allows program to have enough memory as it runs. The CLR also virtualizes our execution environment so we don’t have to worry about things like CPU cores,32bit or 64 bit or what instruction set is available. The CLR will take care of all those things and makes sure that our application will execute correctly.

What is Garbage Collector?

Garbage collector serves as a automatic memory manager. It has the following benefits:

  • It would enable us to develop our application without having to free memory.
  •  It allocates objects on managed heap efficiently.
  •  It reclaims the objects that are no longer being used, clears their memory and keeps the memory available for future allocations.
  •  It provides memory safety by making sure that an object cannot use the context of another object.

What is .NET Framework?

.NET Framework is a software framework developed by Microsoft that can be used to develop business applications, to build games, web applications and apps that can run on different types of phones and mobile devices.

Call a function in child component from parent component in React

Consider the following parent component class Parent extends React.Component { constructor(props) { super(props);         thi...