.NET Core Interview Questions and Answers

We have compiled most frequently asked .NET Interview Questions which will help you with different expertise levels.

.NET Core Interview Questions and Answers PDF Free Download

Question 1.
What is Asp .NET page life cycle?
Answer:
asp .net page life cycle in which it performs a series of processing steps. These include initialization, instantiating controls, restoring and maintaining state, running event handler code, and RENDERING, the asp .net page life cycle include as given below:

A) INITIALIZATION – Init event initializes the control property and the control tree is built. This event can be handled by overloading the Onlnit method or creating a Pagelnit handler.

B) load view state – LoadViewState event allows loading view state information into the controls.

C) load post-back data – During this phase, the contents of all the input fields are defined with the <form> tag are processed.

D) load – The Load event is raised for the page first and then recursively for all child controls. The controls in the control tree are created.

E) Raise postback event – click button event generated

F) save view state – State of control on the page is saved. Personalization, control state, and view state information are saved. The HTML markup is generated. This stage can be handled by overriding the Render method or creating a Page_Render handler.

G) render – html page generated

H) dispose – object associated request cleaned up.

Question 2.
Asp .net validation control & type?
Answer:
ASP.NET provides the following validation controls:

A) Required Field validation – The RequiredFieldValidator control ensures that the required field is not empty, ex.

<asp:RequiredFieldValidator ID=”test”
runat-‘server” ControlToValidate -’ddluser”
ErrorMessage=”Please choose a user”
InitialValue=”Please choose a user”>
</asp:RequiredFieldValidator>

B) Range Validator Control – The Range Validator control verifies that the input value falls within a predetermined range, ex.

<asp:RangeValidator ID="rvclass"
runat="server" ControlToValidate="txtclass"

ErrorMessage="Enter your class (6 - 12)" 
MaximumValue="12"

MinimumValue="6" Type="Integer">

</asp:RangeValidator>

C) Compare validation control – The Compare Validator control compares a value in one control with a fixed value or a value in another control, the specifies the comparison operator, the available values are Equal, NotEqual, Greater Than,
GreaterThanEqual, LessThan, LessThanEqual, and DataTypeCheck..

D) Regular Expression – The RegularExpressionValidator allows validating the input text by matching against a pattern of a regular expression. The regular expression is set in the Validation Expression property.

E) Custom validation – The Custom Validator control allows writing application-specific custom validation routines for both the client-side and the server-side validation, the custom validation is validating against your logic of coding.

F) Validation summary – the validation summary display all error on page COLLECTIVITY.

Question 3.
Write the types of authentication in asp .NET.
Answer:
the following types of authentication are used in asp .net as given below:

A) Windows Authentication – windows authentication is a feature of Windows applications.
B) form base authentication – the user uses the database by validation of the form.
C) passport service – the passport service validates against Microsoft passport services which are basically centralized authentication services.

Question 4.
What is State Management in asp .NET? describe the details.
Answer:
State management means to preserve the state of a control, web page, object/data, and user in the application explicitly because all ASP.NET web applications are stateless, i.e., by default, for each page posted to the server, the state of controls is lost, there is two types of state management in asp .net. client-side state management & server-side state management.

Client-side state management:

A) View state – store user data in user pc. it’s stores data in the generated HTML using hidden files, not on the server, view state provides page-level state management as long as the user is on the current page, the state is available and the user redirects to the next page and the current page state is lost.

B) Control STATE – whichever we developed in the custom control and we want to preserve some information, we can use view state but suppose view is DISABLE EXPLICIT by the user the control will not work.

C) Hidden Field – Hidden field is a control provided by asp .net which is used to store a small amount of data on the client’s pc. it stores one value for the variable and it is a preferable way when a variable’s value is changed frequently.

D) Cookies – A cookie is a small amount of data that is stored either in a text file on the client file system or in-memory in the client browser session. It contains site-specific information that the server sends to the client along with page output. Cookies can be temporary (with specific expiration times and dates) or persistent, cookies to store information about a particular client, session, or application. The cookies are saved on the client device, and when the browser requests a page, the client sends the information in the cookie along with the request information, the default time out of cookies is 30 minutes.

E) Query String – A query string is an information that is appended to the end of a page URL. Query strings provide a simple but limited way to maintain state information. For example, they are an easy way to pass information from one page to another, such as passing a product number from one page to another page where it will be processed.

Server-Side State management:

A) Application state – Application event is written in a special file called global.aspx application file, application state is useful for storing information that needs to be maintained between server round trips and between requests for pages. Application state is stored in a key/value dictionary that is created during each request to a specific URL.

B) Session – session is used to store user information or uniquely identify the users through session id which is store in server only run time. If different users are using your application, each user session will have a different session state, the default time out of the session is 20 minutes.

Question 5.
Types of cookies in asp .net?
Answer:
there are two types of cookies in asp .net. persistent cookies & nonpersistent cookies.

A) persistent cookies – the persistent cookies are permanent cookies store AS A text file in the hard disk of the computer.
B) not persistent cookies – they are temporary cookies store in memory as per session-based cookies, these cookies are active as long as the browser remains active if the browser closed cookies will automatically expire.

Question 6.
What are generics?
Answer:
Answer: The generic allows you to delay the specification of the data type programming elements in class or method until it’s actually used in the program or generics allow you to write a class or method that can work with any data type. EX.

public static void Main( )
{
Generic<string> g = new Generic<string>( );
g.Field = "A new string";
//...
Console.WriteLine("Generic.Field = \"{0}\"", g.Field);
Console. WriteLine("Generic.Field.GetType() = {0}", g.Field.GetType().FullName);
}

Question 7.
What is THREAD?
Answer:
The thread is defined as the execution path of the program, each thread defines a unique flow of control, each thread performed a particular job. thread is a lightweight process, the uses of threads serve wastage of cpu cycle and increase the efficiency of an application.

Question 8.
What is namespace?
Answer:
.Net framework uses a namespace to organize its many classes, the namespace allows you to create a system to organized your code. The System namespace contains fundamental classes and base classes that define commonly-used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions.

Question 9.
Constructor in C# define?
Answer:
When class & structure is created. ITs constructor CALLED CONSTRUCTOR FLAVE the same name as the class or structure and they usually initialize the data member of the new object. Constructors enable the programmer to set default values, limit instantiation, and write code that is flexible and easy to read.

If you don’t provide a constructor for your struct, C# relies on an implicit parameterless constructor to automatically initialize each field of a value type to its default value as listed in the Default Values Table.

Static constructor: A class or struct can also have a static constructor, which initializes static members of the type. Static constructors are parameterless. If you don’t provide a static constructor to initialize static fields, the C# compiler initializes static fields to their default value as listed in the Default Values Table.

Question 10.
Date Set, Data Reader, Data table, Property define?
Answer:
Data Set – DataSet, which is an in-memory cache of data retrieved from a data source, is a major component of the ADO.NET architecture. The DataSet consists of a collection of DataTable objects that you can relate to each other with DataRelation objects. A DataSet can read and write data and schema as XML documents.

Data reader – the data reader used for data reading from retrieve data.

Data Table – The DataTable is a central object in the ADO.NET library. Other objects that use the DataTable include the DataSet and the DataView. DataTable objects are that they are conditionally case sensitive.

Property – The language defines a syntax that enables developers to write code that accurately expresses their design intent. The property is the main part of c# coding. Properties behave like fields when they are accessed. However, unlike fields, properties are implemented with assessors that define the statements executed when a property is accessed.

Question 11.
Different between namespace & Assembly?
Answer:
The namespace provides the fundamental unit of logic code grouping while an assembly provides a fundamental unit of physical code grouping, namespace is a logical group of related classes that can be used by any other language targeting the Microsoft .net framework.

Question 12.
What is string & string Builder?
Answer:
The string is a sequential collection of characters that is used to represent text. The maximum size of a String object in memory is 2GB or about 1 billion characters

The string builder object is not a string but rather an auxiliary object used for manipulating characters, it contains a buffer typically initialized with a string but usually larger than a string.

substring that begins at a specified character position and ends before the end of the string, call the Substring(Int32, Int32) method.

Question 13.
write a common control event in asp .net & Page Control Events?
Answer:

Event Attribute Page Control Events
Click OnClick Data Binding
Command OnCommand Disposed
Text Changed On Text Changed Error
Select     Index    Changed On Select Index Changed IN IT
Checked Changed On Checked Changed Load & Preload

Question 14.
Difference between Interface & Abstract Class?
Answer:

SL Abstract Class Interface
1 Abstract class does not support multiple inheritances. Interface support multiple inheritances.
2 abstract class contains data members. Interface does not
3 abstract class contain a constructor the interface does not contain a constructor.
4 it’s containing classes completed & INCOMPLETE. the interface contains only completed class
5 only complete members of the abstract class can be static. the member of the interface can’t be static.

Question 15.
Write the type of session in ASP .Net?
Answer:
In-process – the session default store in web configure file. OutProc – data store in server-side.
SQL Server/State Server – store in the database this session stores permanently in the database.
Custom mode – we can save session value as per custom mode in our pc or user define LOCATION.

Question 16.
Define MSIL?
Answer:
Microsoft intermediate language (MSIL) we can call Its intermediate language(IL) common intermediate language during the compile time, the compiler converts to source CODE INTO Microsoft intermediate language. MSIL is a CPU independence set of instructions that can be efficiently converted to the native code.

Question 17.
What are Assembly & Types of Assembly?
Answer:
The assembly is a file that is automatically generated by the compilation of every .net application, it can be either dynamic link library (DLL) or on the executable file. IT’S GENERATED only once for an application and upon each subsequent compilation, the assembly gets updated either process will run in the background of your application.

There are two types of assembly.

A) Private assembly – they are simple and copied with each calling assembly in the calling folder.
B) Shared Assembly – the shared assembly is copied to a single location for all calling assemblies within the same application, the same copy of the shared assembly is used from its original location.

Question 18.
What is garbage collection?
Answer:
When you create an object in C# (CLR) allocates memory for the object from heap, this process is repeated for each newly created object, but there is a limitation and we need to be clean some used space in order to make room for new objects, here the concept of garbage collection introduced, the garbage collection managed allocation and reclaiming of memory.

Question 19.
What is the static class?
Answer:
Static class can only contain static data member static method & static constructor, we can use static keyword it’s not allowed to create an object of the static class, the static class are sailed class means you can’t inherit a static class from non-static class.

Question 20.
Cashing in C# and using of cashing?
Answer:
The web browser typically uses a cache to make the web page load faster by sorting a copy of the webpage files locally, such as a local computer. Starting cashing is the process of sorting data into cache working, three types of cashing use in the process, object cashes, Memory cashes & caches items.

Question 21.
What is ado .net?
Answer:
The ADO.NET is a data access technology of Microsoft. ADO.NET is a module of .Net Framework which is used to establish connections between applications and data sources. Data sources can be such as SQL Server and XML. ADO.NET consists of classes that can be used to connect, retrieve, insert and delete data.

Question 22.
What are ASP built-in objects?
Answer:
ASP built-in objects that are available to ASP pages. Using ASP built-in objects, you can access information regarding the Web server, the client who is accessing a Web page, the Web application that contains the Web page, and the fields in the HTTP request and response streams. The ASP built-in objects are organized by the type of information they contain. The information in ASP built-in objects can also be obtained in a COM component or an ISAPI application.

Question 23.
What is Connected & Disconnected Architecture of ADO.NET?
Answer:
The architecture of ADO.net, in which connection must be opened to access the data retrieved from the database is called connected architecture. The connected architecture was built on the classes connection, command, DataReader, and transaction. DataReader is a “connected” approach

Ex: Connected = Make CONNECTION, Keep Connection ALIVE, Close Connection when close is called.

The architecture of ADO.net in which data retrieved from the database can be accessed even when the connection to the database was closed is called disconnected architecture. The disconnected architecture of ADO.net was built on classes connection, DataAdapter, command builder, and dataset and data view. the dataset is a “disconnected” approach

Ex: Disconnected = Make CONNECTION, Fetch DATA, Close Connection.

Question 24.
The difference between Data readers & Data Adapters?
Answer:
Data Reader to retrieve a read-only, forward-only stream of data from a database. Results are returned as the query executes, and are stored in the network buffer on the client until you request them using the Read method of the Data Reader. Using the Data Reader can increase application performance both by retrieving data as soon as it is available.

DataAdapter is used to retrieve data from a data source and populate tables within a DataSet. The DataAdapter also resolves changes made to the DataSet back to the data source. The DataAdapter uses the Connection object of the .NET Framework data provider to connect to a data source, and it uses Command objects to retrieve data from and resolve changes to the data source.

Question 25.
Can we create multiple web. config in a project?
Answer:
Yes, We have one main configuration file (Web. Config), then we have two more configurations files. App.Config and Database.Config. in App. Config we defined all the application-level settings, in the Database. Config we define all the database level settings. And in Web. Config we refer App. Config and Database.Config like this:
Ex:

<appSettings configSource="app.config">
</appSettings>
CconnectionStrings configSource="database.config">
</connectionStrings>

Question 26.
What is the Global.asax file?
Answer:
global.asax allows us to write event handlers that react to global events in web applications. Global.asax files are never called directly by the user, rather they are called automatically in response to application events. They do not contain any HTML or ASP.NET tags. They are optional, but a web application has no more than one global.asax file, a few lists of events global.asax like Application_Start,Aplication_End,Session_Start,Session_End,Application BeginRequest,Application AuthenticateRequest,Applic ationError, Applicantion_ Authorize Request etc.

Question 27.
What is a delegate in C# .NET?
Answer:
A delegate is a type-safe function pointer this is a hold reference pointer to a function, delegate is similar to a class you can create an instance of it. the delegate point to the function. A delegate can be declared using the delegate keyword followed by a function signature
Syntax:

<access modifier> delegate <return type >
<delegate_name>(<parameters>)

Question 28.
What is a property in .Net?
Answer:
A property in C# is a member of a class that provides a flexible mechanism for classes to expose private fields. Internally, C# properties are special methods called accessors. A C# property has two accessors, get property accessor and set property accessor. A get accessor returns a property value, and a set accessor assigns a new value.

Question 29.
What is a collection in C#?
Answer:
Collection classes are specialized classes for data storage and retrieval. These classes provide support for stacks, queues, lists, and hash tables. Most collection classes implement the same interfaces. Collection classes serve various purposes, such as allocating memory dynamically to elements and accessing a list of items on the basis of an index, etc.

Question 30.
How to Improve Application Speed in .NET Technology?
Answer:
The details as given below:

  • Avoid Session & Application Variable.
  • Use Caching, CSS-based layout & JavaScript for validation.
  • Use SP, XML, XSLT format, use data set & clean garbage collection.
  • Use String builder, Threads & avoid bulk data upload on server-side.

Question 31.
You need to select a class that is optimized for key-based item retrieval from both small and large collections. Which class should you choose?
A .OrderedDictionary class
B. HybridDictionary class
C. ListDictionary class
D. Hashtable class
Answer:
B. HybridDictionary class

Question 32.
Which of the following is a dictionary object?
A. HashTable
B. SortedList
C. NameValueCollection
D. All of the above
Answer:
D. All of the above

Question 33.
Which delegate is required to start a thread with one parameter?
A. ThreadStart
B. ParameterizedThreadStart
C. ThreadStartWithOneParameter
D. None of the above
Answer:
B. ParameterizedThreadStart

Question 34.
Why should you write the cleanup code in the Finally block?
A. Compiler throws an error if you close the connection in the try block.
B. Resource cannot be destroyed in the catch block.
C. Finally blocks run whether or not the exception occurs.
D. All of the above
Answer:
C. Finally blocks run whether or not the exception occurs.

Question 35.
Which method is used to dynamically register client script from code?
A. Page.ClientScript.RegisterClientScriptBlock
B. RegisterScript
C. Page.ClientScript
D. None of the above
Answer:
A. Page.ClientScript.RegisterClientScriptBlock

Question 36.
To implement a specified .NET Framework interface which directive is used?
A. @Register
B. @Control
C. @Reference
D. @Implements
Answer:
B. @Control

Question 37.
Which file is used to write the code to respond to the application start event?
A. Any ASP.NET web page with an .aspx extension
B. Web. config
C. Global.asax
D. None of the above.
Answer:
C. Global.asax

Question 38.
Attribute must be set on a validator control for the validation to work.
A. ControlToValidate
B. ControlToBind
C. ValidateControl
D. Validate
Answer:
B. ControlToBind

Question 39.
What is used to validate complex string patterns like an e-mail address?
A. Extended expressions
B. Basic expressions
C. Regular expressions
D. Irregular expressions
Answer:
C. Regular expressions

Question 40.
Why is Global.asax is used?
A. Declare Global variables
B. Implement application and session-level events
C. No use
Answer:
B. Implement application and session-level events

Question 41.
Which DLL translates XML to SQL in IIS?
A. SQLISAPI.dll
B. SQLXML.dll
C. LISXML.dll
D. SQLIIS.dll
Answer:
A. SQLISAPI.dll

Question 42.
Which of the following ASP.NET object encapsulates the state of the client?
A. Session object
B. Application object
C. Response object
D. Server object
Answer:
A. Session object

Question 43.
Which of the following are the performance attributes of the process model?
A. request queue limit
B. max worker threads
C. max threads
D. All
Answer:
D. All

Question 44.
Which of the following is the way to monitor the web application?
A. MMC Event viewers
B. Performance logs
C. Alerts Snap-ins
D. ALL
Answer:
D. ALL

Question 45.
The ____________ property affects how the .Net The framework handles dates, currencies, sorting, and formatting issues.
A. CurrentUICulture
B. CurrentCulture
Answer:
A. CurrentUICulture

Question 46.
How to swap two numbers in C# without using 3rd variable.
Answer:
Input value 100 & 200;

Using System;
Class Swap1
{
Static void main (string [ ] args)
}
int first, second;
First = 100;
Second = 200;
First = first + second;
Second = first - second;
Second = first - second;
Console.writeLine (First.ToString( )) ;
Console.writeLine(Second.ToString( ));
Console.ReadLine( );
}}

Output: 200,100

Question 47.
How to remove duplicate characters from String in C#?
Answer:
Input: Google, Yahoo, BBC

Using system;
Class duplicate1
{
static void main ( )
{
String value1 = RemoveDuplicateChars(“Google”);
String Value2 =RemoveDuplicateChars(“Yahoo”);
String Value3 =RemoveDuplicateChars(“BBC”);
String Value4
=RemoveDuplicateChars(“Linel\Line2\Li ne3”);
Console.writeLine(value1);
Console.writeLine(value2);
Console.writeLine(val ue3);
Console.writeLine(val ue4);
}
StaticstringRemoveDuplicateChars(stri ngkey) //
using for remove duplicate characters.
Stringtable The result will be store.
foreach(charval ue in key) // loop over each characters.

if (table.indexof(value)==-l) // see if
character is in the table.
{
table + = value ;// append to the table and result.
result + = value;
}
}
Returnresult;
}
}

Output: Gogle, Yaho, BC

Question 48.
How to calculate factorial using recursion in C# programming?
Answer:
Enter The Number: 5

Using system;
Using system.collection.generic;
Using system.linq;
Using system.text;

Namespace factorial1
{
Class program
{
Static void Main (string [ ]args)
{
int i, number, fact;
Console.writeLine(“Enter The Number”);
number = int.Parse(Console.Read.Line( ));
fact = number;
for (i = number -1; i> = 1; i- -)
{
fact = fact*1;
}
Console.writeLine(“\n factorial of given number is : “+fact);

Console.ReadLine( );
}
}
}

Output:
Enter The Number: 5
Factorial of the given number is: 120

Question 49.
How to check if a number is Armstrong or not?
Answer:
Input: Enter the Number : 371

Using system;
Using system.collection.generic;
Using system.linq;
Using system.text;

Namespace Armstrong
{
Class program
{
Static void Main (string [ ] args)
{
Int number, remainder, sum = 0;
Console.Write(“Enter The Number”);
number = int.Parse(Console.ReadLine( ));
for (int i = number; i>0; i= i/10)
{
reminder = i%10;
sum = sum + remi nder*reminder*reminder;
}
if (sum == number)
Console.writeLine(“Enter Number is Armstrong Number”);
}
else
Console.writeLine(“Enter number is not Armstrong number”);
cousole.ReadLine();
}
}
}

Output: Enter number is Armstrong number.

Question 50.
Algorithm to check if a number is prime or not?
Answer:
Input: Enter The Number: 11

Using system;
Namespace example
{
Class prime
{
Public static void Main ( )
{
Console.Write.Line(“Enter The Number:”);
Int num // local variable is num.
num = Convert.ToString32(Console.ReadLine( )) ;
int = k;
k = 0;
for( int i = 1; i<= num/2; i++)
{
If (num%i==0)
{
K++ ;
}
}
If(k==2)
{
Console.Write.Line(“Enter Number is Prime Number”);
}
else
{
Console.write.Line(“Enter Number is not Prime Number”);
}
Console.Read.Line( ) ;
}
}
}

Output: Enter Number is Prime Number

Question 51.
Write an algorithm to check if a number is a palindrome or not?
Answer:
Input: Civil, Level, Radar, Apple, Stats, Mango.

using System;
Class palindrome
{
Public static bool lsPalindrome(string word)
{
int min = 0;
int max = word, length-1;
while(true)
{
if(min> max)
{
return true;
}
Char a = word[min];
Char b = word[max];
if (Char.ToString(a) != Char.ToLower(b))
{
return false;
}
Min ++;
Max - - ;
}
}
String void Main ( )
{
String [ ] array = “Civil”,” Level”,” Radar”,” Apple”,” State”,” Mango”,””};
Console.WriteLine(“{0}={l}”, value, isPalindrome (value);
}
}
}

Output:
Civil = True
Level = True
Radar = True
Apple = false
Stats = True
Mango = false

Question 52.
How to find out the sum of digits of a number using recursion?
Answer:
Input = Enter the number 1239

Using system;
Class digit
{
Public static void Main( )
{
Int num, result;
Pro pg = new pro( );
Console.write(“Enter The Number”);
number = int.Parse(Console.ReadLine( ));
result = pg.sum(num);
Console.WriteLine(“Sum of Digits in {0} is {1}”, num, result);
Console.ReadLine( );
}
}
Class pro
{
Public int sum (int num)
{
lf(num ! = 0)
{
Return (num%10 + sum (num/10));
}
else
return 0;
}
}
}

Output: The sum of digits is 1239 is 15.

Question 53.
Write a function to count a total number of set bits in 32 bits’ integer? (Bit Count Algorithms)
Answer:

Using System;
Namespace console application
{
Class bit count
{
Static void Main ( )
{
Console.writeLine(SparseBltcount(0));
Console.writeLine(SparseBitcount(1));
Console.writeLine(SparseBitcount(i nt.Maxval ue))
;
Console.WriteLine(SparseBltcount(256));
Console.ReadLine();
}
Static int SparseBitCount(int n)
{
int count = 0;
while (n! =0)
{
Count ++;
N& = (n-1);
}
Return count;
}
}
}

Output:
0
1
31
1
Press key to continuous………

Question 54.
Write a function to print the nth number in the Fibonacci series.
Answer:
Fibonacci series is a sequence of numbers in below order: 0,1,1,2,3,5,8,13,21,34…. the next number is found by adding up the two numbers before it.
Formula: f(n) = f(n-l)+f(n-2)

Using system;
Using system.collection.generic;
Using system.linq;
Using system.text;

Namespace Fibonaccil
{
Class program1
{
Public static int FibonacciSrties (int i)
{
if(n==0) return 0; //To Return first Fibonacci number. .
if(n==l) return 0; //To Return Second Fibonacci number.
Return Fibonacci Series(n-l) +
FibonacciSeries(n-2);
Public static void Main (string [] args)
{
Console.WriteLine(“Enter the Length of Fibonacci”);
int length =
Convert.Toln132((console.ReadLi ne));
For (int 1=0; i< length; i++)
{
Console.Write(“{0}”, FibonacciSeries(i));
}
Console.ReadKey( );
}
}
}

Question 55.
Write Basic Syntax of Dot Net Technology Example?
Answer:
The Syntax of if-else Condition:

• If(boolen_expression)
{
True block Statement(s)
else
False Block Statement(s)
}
Statement x


• Switch Statement Syntax:


Switch(Expression)
{
Case1 value: block1
break;
Case2 value: block2
break;
default: default-block
break;
}