0% found this document useful (0 votes)
9 views53 pages

Questions

Main questions

Uploaded by

Sandeep Sandy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views53 pages

Questions

Main questions

Uploaded by

Sandeep Sandy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 53

Page |1

INTERVIEW QUESTIONS
Page |2

Contents
1. TUPLES.................................................................................................................................................4
1.1 TUPLE VS ARRAY.........................................................................................................................4
2. VALUE TYPE AND REFERENCE TYPE....................................................................................................6
3. DELEGATES..........................................................................................................................................8
4. BOXING AND UNBOXING..................................................................................................................10
5. MANAGED AND UNMANAGED CODE...............................................................................................11
6. DIFF BETWEEN STRUCT AND CLASS..................................................................................................12
7. ENUM................................................................................................................................................14
8. CONSTANT VS READONLY.................................................................................................................16
9. MVC FILTERS.....................................................................................................................................17
10. ATTRIBUTE ROUTING IN MVC.......................................................................................................18
11. ACTION FILTERS TYPE IN MVC AND RETURN TYPE.......................................................................19
12. WHY MAIN METHOD SHOULD BE STATIC.....................................................................................20
13. TYPE OF CONSTRUCTORS IN CLASS EXPLAIN................................................................................21
14. STATE MANAGEMENT TECHNIQUES.............................................................................................22
15. SEALED CLASS AND PROPERTIES...................................................................................................23
16. DISPOSE AND FINALIZE.................................................................................................................25
17. DELEGATES AND EVENTS..............................................................................................................26
18. C# COLLECTIONS............................................................................................................................27
19. INTERFACE CAN HAVE SAME METHOD.........................................................................................29
20. THREADS.......................................................................................................................................30
21. WEB CONFIG VS MACHINE CONFIG VS APP CONFIG....................................................................35
22. SQL STATEMENT DDL, DML, TCL, DQL, DCL..................................................................................37
23. CLUSTERED AND NON-CLUSTERED INDEX....................................................................................38
24. COLUMN CONSTRAINTS IN SQL....................................................................................................39
25. NORMALIZATION IN SQL...............................................................................................................40
26. SELECTORS IN JQUERY AS WELL CSS.............................................................................................41
The element Selector............................................................................................................................41
The #id Selector....................................................................................................................................41
The .class Selector.................................................................................................................................41
27. FUNCTION VS STORE PROCEDURE IN SQL....................................................................................42
28. THROW EX VS THROW DIFFERENCE IN C#....................................................................................43
29. CAN WE HAVE MULTIPLE EXCEPTION BLOCK...............................................................................44
30. CUSTOM ATTRIBUTES IN C# .........................................................................................................45
Page |3

31. CONVERT.TOSTRING VS TOSTRING DIFFERENCE..........................................................................46


32. SOLID PRINCIPAL...........................................................................................................................47
33. OOPS CONCEPT IN DETAIL............................................................................................................50
Page |4
Page |5

1. TUPLES

so it would be allocated on the heap rather than the stack


Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> -- instance

public static Tuple < string, string, int > GetTupleMethod() {


// Create a 3-tuple and return it
var author = new Tuple < string, string, int > ("Mahesh Chand", "Programming
C#", 2002);
return author;
}

// tuple return type


public(string name, string title, long year) TupleReturnLiteral(long id) {
string name = string.Empty;
string title = string.Empty;
long year = 0;
if (id == 1000) {
name = "Mahesh Chand";
title = "ADO.NET Programming";
year = 2003;
}
return (name, title, year);
}

var numbers = Tuple.Create(1, 2, Tuple.Create(3, 4, 5, 6, 7, 8), 9, 10, 11, 12, 13 );


numbers.Item1; // returns 1
numbers.Item2; // returns 2
numbers.Item3; // returns (3, 4, 5, 6, 7, 8)
numbers.Item3.Item1; // returns 3
numbers.Item4; // returns 9
numbers.Rest; // returns (13)
numbers.Rest.Item1; //returns 13
1.1 TUPLE VS ARRAY
Page |6

Tuple:
enum MyType {
case A, B, C
}
func foo() -> (MyType, Int, String) {
// ...
return (.B, 42, "bar")
}
let (type, amount, desc) = foo()

Array:
func foo() -> [Any] {
// ...
return [MyType.B, 42, "bar"]
}

let result = foo()


let type = result[0] as MyType, amount = result[1] as Int, desc = result[2] as String
Page |7

2. VALUE TYPE AND REFERENCE TYPE


value type:
public class Program
{
static void ChangeValue(int x)
{
x = 200;
Console.WriteLine(x);
}
public static void Main()
{
int i = 100;
Console.WriteLine(i);
ChangeValue(i);
Console.WriteLine(i);
}
}
output:100
200
100

reference type
public class Student{
public string StudentName { get; set; }
}
public class Program{
public static void ChangeReferenceType(Student std2){
std2.StudentName = "Steve";
}
public static void Main(){
Student std1 = new Student();
std1.StudentName = "Bill";
ChangeReferenceType(std1);
Console.WriteLine(std1.StudentName);
}
}
output:
Steve
Page |8

static void ChangeReferenceType(string name)


{
name = "Steve";
}

static void Main(string[] args)


{
string name = "Bill";
ChangeReferenceType(name);
Console.WriteLine(name);
}

output:
Steve
Note: here we are passing string not the class
Page |9

3. DELEGATES

Delegate declaration determines the methods that can be referenced by the


delegate. A delegate can refer to a method, which has the same signature as that
of the delegate.
What if we want to pass a function as a parameter? How does C# handle the
callback functions or event handler? The answer is - delegate.

using System;

delegate int NumberChanger(int n);


namespace DelegateAppl {

class TestDelegate {
static int num = 1;

public static int AddNum(int p) {


num += p;
return num;
}

public static int MultNum(int q) {


num *= q;
return num;
}

public static int getNum() {


return num;
}

static void Main(string[] args) {


//create delegate instances
NumberChanger nc1 = new NumberChanger(AddNum);
NumberChanger nc2 = new NumberChanger(MultNum);

//calling the methods using the delegate objects


nc1(25);
Console.WriteLine("Value of Num: {0}", getNum());
nc2(5);
P a g e | 10

Console.WriteLine("Value of Num: {0}", getNum());


Console.ReadKey();
}
}
}

Output:
Value of Num: 26
Value of Num: 130
P a g e | 11

4. BOXING AND UNBOXING

boxing and unboxing is that boxing is a conversion from a value type to an object
type, whereas the term unboxing refers to the conversion from an object type to
a value type.

int i = 10;
object o = i; //performs boxing

ArrayList list = new ArrayList();


list.Add(10); // boxing
list.Add("Bill");

https://www.tutorialsteacher.com/Content/images/articles/csharp/boxing.PNG

object o = 10;
int i = (int)o; //performs unboxing

int i = 10;
object o = i; // boxing
double d = (double)o; // runtime exception

int i = 10;
object o = i; // boxing
double d = (double)(int)o; // valid

https://www.tutorialsteacher.com/Content/images/articles/csharp/
unboxing.PNG
P a g e | 12

5. MANAGED AND UNMANAGED CODE

Managed code is the one that is executed by the CLR of the .NET framework while
unmanaged or unsafe code is executed by the operating system.

What are the advantages of using Managed Code?


 It improves the security of the application like when you use runtime
environment, it automatically checks the memory buffers to guard against
buffer overflow.
 It implements the garbage collection automatically.
 It also provides runtime type checking/dynamic type checking.
 It also provides reference checking which means it checks whether the
reference point to the valid object or not and also check they are not
duplicate.
What are the disadvantages of Managed Code?
The main disadvantage of managed language is that you are not allowed to
allocate memory directly, or you cannot get the low-level access of the CPU
architecture.

What are the advantages of using Unmanaged Code?


 It provides the low-level access to the programmer.
 It also provides direct access to the hardware.
 It allows the programmer to bypass some parameters and restriction that are
used by the managed code framework.
What are the disadvantages of Unmanaged Code?
 It does not provide security to the application.
 Due to the access to memory allocation the issues related to memory occur
like memory buffer overflow, etc.
 Error and exceptions are also handled by the programmer.
 It does not focus on garbage collection.
P a g e | 13

6. DIFF BETWEEN STRUCT AND CLASS

One major difference between structs and classes is that structs are value types,
while classes are reference types. This means that structs are copied by value
when they are passed around, while classes are copied by reference.
Class Structure
Classes are of reference types. Structs are of value types.

All the reference types are allocated on heap All the value types are allocated on stack
memory. memory.

Allocation of large reference type is cheaper Allocation and de-allocation is cheaper in


than allocation of large value type. value type as compare to reference type.

Class is generally used in large programs. Struct are used in small programs.
Structure does not contain parameter less
constructor or destructor, but can contain
Classes can contain constructor or destructor.
Parameterized constructor or static
constructor.
Classes used new keyword for creating Struct can create an instance, with or
instances. without new keyword.
A Struct is not allowed to inherit from
A Class can inherit from another class.
another struct or class.
The data member of struct can’t be
The data member of a class can be protected.
protected.
Function member of the class can be virtual Function member of the struct cannot be
or abstract. virtual or abstract.

Each variable in struct contains its own copy


Two variable of class can contain the
of data(except in ref and out parameter
reference of the same object and any operation
variable) and any operation on one variable
on one variable can affect another variable.
cannot effect another variable.
P a g e | 14

struct Employee {
public int id;
}

using System;
namespace VariablesDemo
{
internal class Example
{
int x = 10;
static void Main(string[] args)
{
Example e1 = new Example(); //e1 is Instance of class Example
Example e2 = e1; //e2 is Reference of class Example

Console.WriteLine($"e1.x: {e1.x} and e2.x: {e2.x}");

e1.x = 50; //Modifying the x variable of e1 instance


Console.WriteLine($"e1.x: {e1.x} and e2.x {e2.x}");

Console.ReadKey();
}
}
}

Last point example: for Classes


P a g e | 15

7. ENUM
An enum is a special "class" that represents a group
of constants (unchangeable/read-only variables).
Example:
enum WeekDays
{
Monday, // 0
Tuesday, // 1
Wednesday, // 2
Thursday, // 3
Friday, // 4
Saturday, // 5
Sunday // 6
}

enum Categories
{
Electronics, // 0
Food, // 1
Automotive = 6, // 6
Arts, // 7
BeautyCare, // 8
Fashion // 9
}

Example: Enum Conversion


enum WeekDays
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
P a g e | 16

Console.WriteLine(WeekDays.Friday); //output: Friday


int day = (int) WeekDays.Friday; // enum to int conversion
Console.WriteLine(day); //output: 4

var wd = (WeekDays) 5; // int to enum conversion


Console.WriteLine(wd);//output: Saturday
P a g e | 17

8. CONSTANT VS READONLY

In C#, constant fields are created using const keyword. ReadOnly is a runtime
constant. Const is a compile time constant. The value of readonly field can be
changed.

using System.IO;
using System;
public class Program {
public const int VALUE = 10;
public readonly int value1;

Program(int value){
value1 = value;
}
public static void Main() {
Console.WriteLine(VALUE);
Program p1 = new Program(11);
Console.WriteLine(p1.value1);
}
}
P a g e | 18

9. MVC FILTERS

In ASP.NET MVC, a user request is routed to the appropriate controller and


action method. However, there may be circumstances where you want to
execute some logic before or after an action method executes. ASP.NET MVC
provides filters for this purpose.
throw new Exception("This is unhandled exception");
Filter Type Description Built-in Filter Interface
Performs
authentication and
authorizes before
Authorization executing an action [Authorize],
filters method. [RequireHttps] IAuthorizationFilter
Performs some
operation before
and after an action
Action filters method executes.
Performs some
operation before or
after the execution
Result filters of the view. [OutputCache] IResultFilter
Performs some
operation if there is
an unhandled
exception thrown
during the execution
Exception of the ASP.NET MVC
filters pipeline. [HandleError] IExceptionFilter

Example: Authorization filters


public class SessionExpirationFilter : ActionFilterAttribute {
public override void OnActionExecuting(ActionExecutingContext filterContext) {
if (HttpContext.Current.Session["UserId"] == null) {
filterContext.Result = new RedirectResult("~/Login/LogOut");
return;
}
base.OnActionExecuting(filterContext);
}
}
P a g e | 19

10. ATTRIBUTE ROUTING IN MVC

Attribute routing uses attributes to define routes. Attribute routing gives you
more control over the URIs in your web API. For example, you can easily create
URIs that describe hierarchies of resources.

Example:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "about", id = UrlParameter.Optional } //
Parameter defaults
);
P a g e | 20

11. ACTION FILTERS TYPE IN MVC AND RETURN TYPE

Type (Return Type) Helper Method Description


ViewResult View() To return the view from action
PartialViewResult PartialView() It is useful to return partial view.
ContentResult Content() To return simple text
RedirectResult Redirect() To redirect the user to a url
RedirectToRouteResul
t RedirectToAction() To redirect an action instead of url
JsonResult Json() To return serialize json object
FileResult File() To return file
HttpNotFoundResult HttpNotFound() To return not found or 404 error
It is used when an action doesn’t need
EmptyResult to return any values like void.

Refer
https://www.c-sharpcorner.com/article/action-results-and-action-filters-in-asp-
net/
P a g e | 21

12. WHY MAIN METHOD SHOULD BE STATIC

Main() method must be static because it is a class level method. To invoked


without any instance of the class it must be static. Non-static Main() method will
give a compile-time error. Main() Method cannot be overridden because it is the
static method.

using system;
namespace demo {
class helloworld {
static void main(string[] args) {
console.writeline("hello world");
console.readkey();
}
}
}
P a g e | 22

13. TYPE OF CONSTRUCTORS IN CLASS EXPLAIN

A special method of the class that is automatically invoked when an instance of


the class is created is called a constructor. The main use of constructors is to
initialize the private fields of the class while creating an instance for the class.
When you have not created a constructor in the class, the compiler will
automatically create a default constructor of the class. The default constructor
initializes all numeric fields in the class to zero and all string and object fields to
null.
1. Default Constructor
2. Parameterized Constructor
3. Copy Constructor
4. Static Constructor
5. Private Constructor

public addition() { } //default contructor


public paraconstrctor(int x, int y) // decalaring Paremetrized Constructor with ing
x,y parameter
paraconstrctor v = new paraconstrctor(100, 175); // Creating object of
Parameterized Constructor and ing values
public employee(employee emp) // declaring Copy constructor.
{
name = emp.name;
age = emp.age;
}
public employee(string name, int age) // Instance constructor.
{
this.name = name;
this.age = age;
}
employee emp1 = new employee("Vithal", 23); // Create a new employee object.
employee emp2 = new employee(emp1); // here is emp1 details is copied to
emp2.

static employee() { } // Static constructor


P a g e | 23

private Counter() { } //private constrctor declaration


P a g e | 24

14. STATE MANAGEMENT TECHNIQUES

Client-Side State Management techniques are,


 View State
 Hidden field
 Cookies
 Control State
 Query Strings

Server-Side State Management techniques are,


 Session State
 Application State
P a g e | 25

15. SEALED CLASS AND PROPERTIES

Sealed classes are used to restrict the users from inheriting the class. A class can
be sealed by using the sealed keyword. The keyword tells the compiler that the
class is sealed, and therefore, cannot be extended. No class can be derived from
a sealed class.
// C# program to
// define Sealed Class
using System;
class Printer {
// Display Function for
// Dimension printing
public virtual void show()
{
Console.WriteLine("display dimension : 6*6");
}
// Display Function
public virtual void print()
{
Console.WriteLine("printer printing....\n");
}
}
// inheriting class
class LaserJet : Printer {
// Sealed Display Function
// for Dimension printing
sealed override public void show()
{
Console.WriteLine("display dimension : 12*12");
}
// Function to override
// Print() function
override public void print()
{
Console.WriteLine("Laserjet printer printing....\n");
}
}
// Officejet class cannot override show
// function as it is sealed in LaserJet class.
P a g e | 26

class Officejet : LaserJet {


// can not override show function or else
// compiler error : 'Officejet.show()' :
// cannot override inherited member
// 'LaserJet.show()' because it is sealed.
override public void print()
{
Console.WriteLine("Officejet printer printing....");
}
}

// Driver Class
class Program {

// Driver Code
static void Main(string[] args)
{
Printer p = new Printer();
p.show();
p.print();

Printer ls = new LaserJet();


ls.show();
ls.print();

Printer of = new Officejet();


of.show();
of.print();
}
}
Output:
display dimension: 6*6
Printer printing....
display dimension: 12*12
LaserJet printer printing....
display dimension: 12*12
Officejet printer printing....
P a g e | 27

16. DISPOSE AND FINALIZE

The C# dispose() and finalize() methods are used to liberate the unmanaged
resources kept by an object. The dispose() method is described within the
IDisposable interface, but the finalize() method is described within the class
object.
Dispose () use to remove the unreachable object from memory or object which
has no references. Dispose (). This method call by Developer. Finalize () clean up
the object from memory which has no references.
BASIS FOR
COMPARISON DISPOSE( ) FINALIZE( )
The method dispose( ) is The method finalize( ) id
defined in the interface defined in java.lang.object
Defined IDisposable interface. class.
public void Dispose( ){ protected void finalize( ){
// Dispose code here // finalization code here
Syntax } }
The method finalize( ) is
The method dispose( ) is invoked by the garbage
Invoked invoked by the user. collector.
Method finalize( ) is used to
Method dispose( ) is used to free unmanaged resources
free unmanaged resources before the object is
Purpose whenever it is invoked. destroyed.
The method dispose( ) is to be The method finalize( ) is to be
implemented whenever there implemented for unmanaged
Implementation is a close( ) method. resources.
The method dispose( ) is The method finalize( ) is
Access specifier declared as public. declared as private.
The method dispose( ) is faster
and instantly disposes an The method finalize is slower
Action object. as compared to dispose
The method disposes( )
performs the instantaneous The method finalize( ) being
action hence, does not effect slower affects the
Performance the performance of websites. performance of the websites.
P a g e | 28

17. DELEGATES AND EVENTS

The applications and windows communicate via predefined messages. These


messages contain various information to determine window and application
actions. The .NET considers these messages as an event. You will handle the
corresponding event if you need to react to a specific incoming message. For
instance, when a button is clicked on a form, Windows sends a WM_MOUSECLICK
message to the button message handler.

Defining an event is a two-step process. First, you need to define a delegate type
that will hold the list of methods to be called when the event is fired. Next, you
declare an event using the event keyword. To illustrate the event, we are creating
a console application. In this iteration, we will define an event to add that is
associated with a single delegate DelEventHandler.

public delegate void DelEventHandler();

public static event DelEventHandler add;

static void Main(string[] args)


{
add += new DelEventHandler(USA);
P a g e | 29

18. C# COLLECTIONS

C# collection types are designed to store, manage and manipulate similar data
more efficiently. Data manipulation includes adding, removing, finding, and
inserting data in the collection. Collection types implement the following common
functionality:

 Adding and inserting items to a collection


 Removing items from a collection
 Finding, sorting, searching items
 Replacing items
 Copy and clone collections and items
 Capacity and Count properties to find the capacity of the collection and
number of items in the collection

The following table lists and matches these classes.

Non-generic Generic

ArrayList -------------> List

HashTable -------------> Dictionary

SortedList -------------> SortedList

Stack -------------> Stack

Queue -------------> Queue

Syntax :

ArrayList al = new ArrayList();


string str = "kiran teja jallepalli";
int x = 7;
DateTime d = DateTime.Parse("8-oct-1985");
al.Add(str);
al.Add(x);
P a g e | 30

al.Add(d);

Hashtable ht = new Hashtable();


ht.Add("ora", "oracle");
ht.Add("ora", "oracle");

SortedList sl = new SortedList();


sl.Add("ora", "oracle");
sl.Add("vb", "vb.net");

Stack stk = new Stack();


stk.Push("cs.net");
stk.Push("vb.net");

Queue q = new Queue();


q.Enqueue("cs.net");
q.Enqueue("vb.net");

Dictionary<int, string> dct = new Dictionary<int, string>();


dct.Add(1, "cs.net");
dct.Add(2, "vb.net");
P a g e | 31

19. INTERFACE CAN HAVE SAME METHOD

Interfaces in C# are provided as a replacement of multiple inheritance. Interface


contains all abstract methods inherited by classes and structs, which must provide
an implementation for each interface member declared. The keyword interface
creates an interface. They are public by default.

Example:
using System;
interface A
{
void Hello();
}

interface B
{
void Hello();
}

class Test : A, B
{
public void Hello()
{
Console.WriteLine("Hello to all");
}
}

public class interfacetest


{
public static void Main()
{
Test Obj1 = new Test();
Obj1.Hello();
}
}
P a g e | 32

20. THREADS

A thread is defined as the execution path of a program. Each thread defines a unique
flow of control. If your application involves complicated and time consuming operations,
then it is often helpful to set different execution paths or threads, with each thread
performing a particular job.
Threads are lightweight processes. One common example of use of thread is
implementation of concurrent programming by modern operating systems. Use of
threads saves wastage of CPU cycle and increase efficiency of an application.

Thread Life Cycle


 The Unstarted State − It is the situation when the instance of the thread is
created but the Start method is not called.
 The Ready State − It is the situation when the thread is ready to run and waiting
CPU cycle.
 The Not Runnable State − A thread is not executable, when
o Sleep method has been called
o Wait method has been called
o Blocked by I/O operations
 The Dead State − It is the situation when the thread completes execution or is
aborted.

The following table shows some most commonly used properties of the Thread
class −

Sr.No.Property & Description


CurrentContext
Gets the current context in which the thread is executing.

CurrentCulture
Gets or sets the culture for the current thread.

CurrentPrinciple
Gets or sets the thread's current principal (for role-based security).

CurrentThread
Gets the currently running thread.

CurrentUICulture
P a g e | 33

Gets or sets the current culture used by the Resource Manager to look up culture-
specific resources at run-time.
ExecutionContext
Gets an ExecutionContext object that contains information about the various
contexts of the current thread.

IsAlive
Gets a value indicating the execution status of the current thread.

IsBackground
Gets or sets a value indicating whether or not a thread is a background thread.

IsThreadPoolThread
Gets a value indicating whether or not a thread belongs to the managed thread
pool.

ManagedThreadId
Gets a unique identifier for the current managed thread.

Name
Gets or sets the name of the thread.

Priority
Gets or sets a value indicating the scheduling priority of a thread.

ThreadState
Gets a value containing the states of the current thread.

The following table shows some of the most commonly used methods of the
Thread class −

Sr.No.Method & Description

public void Abort()


Raises a ThreadAbortException in the thread on which it is invoked, to begin the
process of terminating the thread. Calling this method usually terminates the
thread.

public static LocalDataStoreSlot AllocateDataSlot()


P a g e | 34

Allocates an unnamed data slot on all the threads. For better performance, use
fields that are marked with the ThreadStaticAttribute attribute instead.

public static LocalDataStoreSlot AllocateNamedDataSlot(string name)


Allocates a named data slot on all threads. For better performance, use fields that
are marked with the ThreadStaticAttribute attribute instead.

public static void BeginCriticalRegion()


Notifies a host that execution is about to enter a region of code in which the
effects of a thread abort or unhandled exception might jeopardize other tasks in
the application domain.

public static void BeginThreadAffinity()


Notifies a host that managed code is about to execute instructions that depend
on the identity of the current physical operating system thread.

public static void EndCriticalRegion()


Notifies a host that execution is about to enter a region of code in which the
effects of a thread abort or unhandled exception are limited to the current task.

public static void EndThreadAffinity()


Notifies a host that managed code has finished executing instructions that depend
on the identity of the current physical operating system thread.

public static void FreeNamedDataSlot(string name)


Eliminates the association between a name and a slot, for all threads in the
process. For better performance, use fields that are marked with the
ThreadStaticAttribute attribute instead.

public static Object GetData(LocalDataStoreSlot slot)


Retrieves the value from the specified slot on the current thread, within the
current thread's current domain. For better performance, use fields that are
marked with the ThreadStaticAttribute attribute instead.

public static AppDomain GetDomain()


Returns the current domain in which the current thread is running.

public static AppDomain GetDomainID()


Returns a unique application domain identifier
P a g e | 35

public static LocalDataStoreSlot GetNamedDataSlot(string name)


Looks up a named data slot. For better performance, use fields that are marked
with the ThreadStaticAttribute attribute instead.
public void Interrupt()
Interrupts a thread that is in the WaitSleepJoin thread state.

public void Join()


Blocks the calling thread until a thread terminates, while continuing to perform
standard COM and SendMessage pumping. This method has different overloaded
forms.

public static void MemoryBarrier()


Synchronizes memory access as follows: The processor executing the current
thread cannot reorder instructions in such a way that memory accesses prior to
the call to MemoryBarrier execute after memory accesses that follow the call to
MemoryBarrier.

public static void ResetAbort()


Cancels an Abort requested for the current thread.

public static void SetData(LocalDataStoreSlot slot, Object data)


Sets the data in the specified slot on the currently running thread, for that
thread's current domain. For better performance, use fields marked with the
ThreadStaticAttribute attribute instead.

public void Start()


Starts a thread.

public static void Sleep(int millisecondsTimeout)


Makes the thread pause for a period of time.

public static void SpinWait(int iterations)


Causes a thread to wait the number of times defined by the iterations parameter

public static byte VolatileRead(ref byte address)


public static double VolatileRead(ref double address)
public static int VolatileRead(ref int address)
public static Object VolatileRead(ref Object address)
P a g e | 36

Reads the value of a field. The value is the latest written by any processor in a
computer, regardless of the number of processors or the state of processor cache.
This method has different overloaded forms. Only some are given above.

public static void VolatileWrite(ref byte address,byte value)


public static void VolatileWrite(ref double address, double value)
public static void VolatileWrite(ref int address, int value)
public static void VolatileWrite(ref Object address, Object value)
Writes a value to a field immediately, so that the value is visible to all processors
in the computer. This method has different overloaded forms. Only some are
given above.

public static bool Yield()


Causes the calling thread to yield execution to another thread that is ready to run
on the current processor. The operating system selects the thread to yield to.
P a g e | 37

21. WEB CONFIG VS MACHINE CONFIG VS APP CONFIG

Web.config

It is a configuration file, which is used in web application and it can be an ASP.NET


project or MVC project. Some project contains multiple web.config file inside the
same project but with different folder. They have their unique benefits. You can
create several web.config file in each folder with their unique benefits as per your
project requirement.

It is used to store the application level configuration. Sometimes it inherits the


setting from the machine.config. It parses at runtime, means if you make any
changes then web application will load all the settings in the config file. You don’t
need to create a web.config file because it is auto generated when you create a
new web application. If you want to create a web.config manually you can create
it.

App.config

It is also a special type of configuration file which is basically used with Windows
Services, Windows application, Console Apps or it can be WPF application or any
others.

It parses at compile time; it means if you edit the app.config when program is
running, then you need to restart the application to reload the configuration
setting into the program.

When you run the application which contains the app.config, at the time of
compilation a copy of app.config with different name moves into build folder for
running the application, So that's why we need to restart the program if any
changes made in app.config.

It is not added auto when you create a project, to add this you need to go to
solution explorer and choose Add New Item and choose “Application
Configuration File”. Windows application always contains the App.config file into
the project.
P a g e | 38

Machine.config

It is a special type of configuration file which creates into the OS when you install
visual studio. This stores machine level configuration setting. Only one
machine.config file exists into the system and it stores highest level of
configuration settings.

Machine.config settings apply to all web applications which is residing on the


server. The setting of machine.config can be overridden by web.config’s settings.
If your system does not contain the machine.config then you cannot execute the
application.

Path of Machine.config

32-bit System

%windir%\Microsoft.NET\Framework\[version]\config\machine.config

64-bit System

%windir%\Microsoft.NET\Framework64\[version]\config\machine.config
P a g e | 39

22. SQL STATEMENT DDL, DML, TCL, DQL, DCL

Structured Query Language(SQL) as we all know is the database language by the


use of which we can perform certain operations on the existing database and also
we can use this language to create a database. SQL uses certain commands like
CREATE, DROP, INSERT, etc. to carry out the required tasks.
SQL commands are like instructions to a table. It is used to interact with the
database with some operations. It is also used to perform specific tasks, functions,
and queries of data. SQL can perform various tasks like creating a table, adding
data to tables, dropping the table, modifying the table, set permission for users.
These SQL commands are mainly categorized into five categories:
DDL – Data Definition Language
DQL – Data Query Language
DML – Data Manipulation Language
DCL – Data Control Language
TCL – Transaction Control Language

GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;


REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;
P a g e | 40

23. CLUSTERED AND NON-CLUSTERED INDEX

CLUSTERED INDEX NON-CLUSTERED INDEX


A clustered index is faster. A non-clustered index is slower.
The clustered index requires less memory for A non-Clustered index requires more memory for
operations. operations.
In a clustered index, the clustered index is the In the Non-Clustered index, the index is the copy of
main data. data.

A table can have only one clustered index. A table can have multiple non-clustered indexes.

The clustered index has the inherent ability to A non-Clustered index does not have the inherent
store data on the disk. ability to store data on the disk.
Non-Clustered index storescontainThe non-
Clustered both value and a pointer to the actual
Clustered index store pointers to block not data. row that holds data.
In Non-Clustered index leaf nodes are not the
actual data itself rather they only contain included
In Clustered index leaf nodes are actual data itself. columns.

In a Clustered index, Clustered key defines the In a Non-Clustered index, the index key defines the
order of data within a table. order of data within the index.

A Clustered index is a type of index in which table A Non-Clustered index is a special type of index in
records are physically reordered to match the which the logical order of the index does not match
index. the physical stored order of the rows on the disk.

The size of the non-clustered index is compared


The size of The primary clustered index is large. relativelyThe composite is smaller.
The composite key when used with unique
Primary Keys of the table by default are clustered constraints of the table act as the non-clustered
indexes. index.
P a g e | 41

24. COLUMN CONSTRAINTS IN SQL


P a g e | 42

25. NORMALIZATION IN SQL

Normalization is the process to eliminate data redundancy and enhance data


integrity in the table. Normalization also helps to organize the data in the
database. It is a multi-step process that sets the data into tabular form and
removes the duplicated data from the relational tables.

 First Normal Form


 Second Normal Form
 Third Normal Form
 Boyce Codd Normal Form

Candidate Key
A candidate key is a set of one or more columns that can identify a record
uniquely in a table, and YOU can use each candidate key as a Primary Key.

Super key
Super key is a set of over one key that can identify a record uniquely in a table,
and the Primary Key is a subset of Super Key.
P a g e | 43

26. SELECTORS IN JQUERY AS WELL CSS

jQuery selectors are one of the most important parts of the jQuery library. jQuery
selectors allow you to select and manipulate HTML element(s).

jQuery selectors are used to "find" (or select) HTML elements based on their
name, id, classes, types, attributes, values of attributes and much more. It's based
on the existing CSS Selectors, and in addition, it has some own custom selectors.

All selectors in jQuery start with the dollar sign and parentheses: $().

The element Selector

$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});

The #id Selector

$("#test").hide();

The .class Selector

$(".test").hide();

$("tr:even") Selects all even <tr> elements

$("tr:odd") Selects all odd <tr> elements

$("[href]") Selects all elements with an href attribute

$(this) Selects the current HTML element


P a g e | 44

27. FUNCTION VS STORE PROCEDURE IN SQL

Function Stored Procedure


Always returns a single value; either Can return zero, single or multiple
scalar or a table. values.
Functions are compiled and executed at Stored procedures are stored in parsed
run time. and compiled state in the database.
Can perform any operation on database
Only Select statements. DML statements objects including select and DML
like update & insert are not allowed. statements.
Allows only input parameters. Does not Allows both input and output
allow output parameters. parameters
Does not allow the use of Try…Catch Allows use of Try…Catch blocks for
blocks for exception handling. exception handling.
Cannot have transactions within a Can have transactions within a stored
function. procedure.
Cannot call a stored procedure from a Can call a function from a stored
function. procedure.
Temporary tables cannot be used within
a function. Only table variables can be Both table variables and temporary
used. tables can be used.
Stored procedures cannot be called
from a Select/Where or Having
Functions can be called from a Select statements. Execute statement has to
statement. be used to execute a stored procedure.
Stored procedures cannot be used in
Functions can be used in JOIN clauses. JOIN clauses
P a g e | 45

28. THROW EX VS THROW DIFFERENCE IN C#

throw: If we use "throw" statement, it preserves original error stack information.


In exception handling "throw" with empty parameter is also called re-throwing
the last exception.

throw ex : If we use "throw ex" statement, stack trace of exception will be


replaced with a stack trace starting at the re-throw point. It is used to
intentionally hide stack trace information.
P a g e | 46

29. CAN WE HAVE MULTIPLE EXCEPTION BLOCK

try
{
Console.WriteLine("Enter First Number");
Number1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Second Number");
Number2 = int.Parse(Console.ReadLine());
Result = Number1 / Number2;
Console.WriteLine($"Result: {Result}");
}
catch (DivideByZeroException DBZE)
{
Console.WriteLine("Second Number Should Not Be Zero");
}
catch (FormatException FE)
{
Console.WriteLine("Enter Only Integer Numbers");
}
P a g e | 47

30. CUSTOM ATTRIBUTES IN C#

"Attributes provide a powerful method of associating declarative information with


C# code (types, methods, properties, and so forth). Once associated with a
program entity, the attribute can be queried at run time and used in any number
of ways." - MSDN
Attributes are classes that allow you to add additional information to elements of
your class structure.

// method 1 of our Customer class


[Stereotype("Accessor", "Retrieve the name of the customer")]
public string GetName() {
return Name;
}
// Method 2 of our customer class
[Stereotype("Modifier", "Set the name of the customer")]
public void SetName(string aName) {
Name = aName;
}
P a g e | 48

31. CONVERT.TOSTRING VS TOSTRING DIFFERENCE

Here both the methods are used to convert the string but the basic difference
between them is: "Convert" function handles NULLS, while "i.ToString()" does
not it will throw a NULL reference exception error. So as good coding practice
using "convert" is always safe.

Let's see another example:

string s;
object o = null;
s = o.ToString();
//returns a null reference exception for s.

string s;
object o = null;
s = Convert.ToString(o);
//returns an empty string for s and does not throw an exception.
P a g e | 49

32. SOLID PRINCIPAL

SOLID principles in C#

SOLID design principles in C# are basic design principles.

The following are the design flaws that cause damage to software, mostly.

1. Putting more stress on classes by assigning more responsibilities to them. (A


lot of functionality not related to a class.)
2. Forcing the classes to depend on each other. If classes depend on each other
(in other words, tightly coupled), then a change in one will affect the other.
3. Spreading duplicate code in the system/application.
Solution
1. Choosing the correct architecture (MVC, 3-tier, Layered, MVP, MVVP, and so
on).
2. Following Design Principles.
3. Choosing the correct Design Patterns to build the software based on its
specifications. We go through the Design Principles first and will cover the
rest soon

Introduction to SOLID principles

SOLID principles are the design principles that enable us to manage several
software design problems. Robert C. Martin compiled these principles in the
1990s. These principles provide us with ways to move from tightly coupled code
and little encapsulation to the desired results of loosely coupled and encapsulated
real business needs properly. SOLID is an acronym for the following.

 S: Single Responsibility Principle (SRP)


 O: Open-closed Principle (OCP)
 L: Liskov substitution Principle (LSP)
 I: Interface Segregation Principle (ISP)
 D: Dependency Inversion Principle (DIP)
P a g e | 50

S: Single Responsibility Principle (SRP)


SRP says, "Every software module should have only one reason to change.".

O: Open/Closed Principle
The Open/closed Principle says, "A software module/class is open for extension
and closed for modification."

L: Liskov Substitution Principle


The Liskov Substitution Principle (LSP) states, "you should be able to use any
derived class instead of a parent class and have it behave in the same manner
without modification.". It ensures that a derived class does not affect the
behavior of the parent class; in other words, a derived class must be substitutable
for its base class.
P a g e | 51

I: Interface Segregation Principle (ISP)


The Interface Segregation Principle states "that clients should not be forced to
implement interfaces they don't use. Instead of one fat interface, many small
interfaces are preferred based on groups of methods, each serving one
submodule.".

D: Dependency Inversion Principle

The Dependency Inversion Principle (DIP) states that high-level modules/classes


should not depend on low-level modules/classes. First, both should depend upon
abstractions. Secondly, abstractions should not rely upon details. Finally, details
should depend upon abstractions.
P a g e | 52

33. OOPS CONCEPT IN DETAIL

introduces Object Oriented Programming (OOP) in C#. OOPs is a concept of


modern programming language that allows programmers to organize entities and
objects. Four key concepts of OOPs are abstraction, encapsulation, inheritance,
and polymorphism. Here learn how to implement OOP concepts in C# and .NET.

Here are the key features of OOP:

 Object Oriented Programming (OOP) is a programming model where


programs are organized around objects and data rather than action and logic.
 OOP allows decomposing a problem into many entities called objects and
then building data and functions around these objects.
 A class is the core of any modern object-oriented programming language
such as C#.
 In OOP languages, creating a class for representing data is mandatory.
 A class will not occupy any memory space; hence, it is only a logical
representation of data.

Class - Classes and Objects in C# A class is a data structure in C# that combines


data variables and functions into a single unit
Object - Instances of the class are known as objects. the object is an actual
instantiation of the class and contains data.
Abstraction - Abstraction is "To represent the essential feature without
representing the background details."
 Abstraction lets you focus on what the object does instead of how it does it.
 Abstraction provides a generalized view of your classes or objects by
providing relevant information.
 Abstraction is the process of hiding the working style of an object and
showing the information about an object understandably.

abstract class MobilePhone {


public void Calling();
public void SendSMS();
}
public class Nokia1400: MobilePhone {}
public class Nokia2700: MobilePhone {
P a g e | 53

public void FMRadio();


public void MP3();
public void Camera();
}
public class BlackBerry: MobilePhone {
public void FMRadio();
public void MP3();
public void Camera();
}
Encapsulation

Wrapping up a data member and a method together into a single unit (in other
words, class) is called Encapsulation. Encapsulation is like enclosing in a capsule.
That is, enclosing the related operations and data related to an object into that
object.

Inheritance

When a class includes a property of another class, it is known as


inheritance. Inheritance is a process of object reusability.

Polymorphism

Polymorphism means one name, many forms. One function behaves in different
forms. In other words, "Many forms of a single object is called Polymorphism."

You might also like