You are on page 1of 4

C#:

 
1. When calling async methods, what will you do to make sure the
execution completes before processing the rest of the code?
 Await keyword
2. How will you call REST API methods from C#?
Using httpclient class
3. How will you find whether an array of integers has the integer i am looking for
using LINQ?
Using Contains() method
4. Use of Generics
A generic type is declared by specifying a type parameter in an
angle brackets after a type name, e.g. TypeName<T> where T is a
type parameter.
 Exception handling and logging
 Try catch finally blocks
 Looging can be done by eventlogs
6. How will you make sure an object is disposed?
Finalize : which is called by the Garbage Collector before when application is running
low memory resources
Dispose:by implementing the idispose interface

7. What are extension methods?


C# extension methods allows us to extend functionality of an existing type
without creating a new derived type, recompiling, or otherwise modifying the
original type. C# extension method 
Using static class and this key word as a first parameter tj=o the method we can
create it
8. What is value tuple?
It allows you to store a data set which contains multiple values that may or
may not be related to each other. It can store elements of different types.
9. What are Delegates, Actions, Funcs, Lambdas?
1. The Func delegate takes zero, one or more input parameters, and returns
a value (with its out parameter).
2. Action takes zero, one or more input parameters, but does not return
anything.
3. Predicate is a special kind of Func. It represents a method that contains a
set of criteria mostly defined inside an if condition and checks whether
the passed parameter meets those criteria or not.

10.What is auto implemented properties?


C# 3.0 includes a concept of auto-implemented properties that requires no code
inside get and set methods of the class properties. It makes code readable
11. Can you have more than one catch block in try-catch?
Follow up question: If so, what's the order --> specific to generic or generic to
specific exception?
Yes,exception is the base type so it should below bottom of all exceptions because if
it is in top it can catch all errors it gives compile time error
 

 
MVC:
 

1. Model binding in MVC


Model binding is a process in which we bind a model to controller and
view
2. What are the different types of ActionResult that you can return from
MVC method?

 View Result
 Partial View Result
 Redirect Result
 Redirect To Action Result
 Redirect To Route Result
 Json Result
 File Result
 Content Result
Say i want to download a file on click of a link, what action result you would return?
fileresult
3. Is it possible to have more than one attribute routing for a method?
Yes ,we can take two route attributes
4. What will you do to avoid CORS issue when calling ASP.Net API from Angular
services?
5. Have you noticed web.config in Views folder in MVC app? What does it do?
web.config file exists in the Views folders to prevent access to your views by any means
other than your controller.
In razor syntax, how will you escape HTML elements inside a code block
 ould use @: to escape:
 @if(Model.foo)
 {
 @:Hello World
 }
 or the special <text> tag which is not outputted in the response:
 @if(Model.foo)
 {
 <text>Hello World</text>
 }

7. When the app is running, what will happen if i go and make changes to the
web.config?
Website will restarts,allthe session will loose
8. How will you redirect the users to custom pages based on the http error code?
Using redirect result we can redirect in exception filter
1.  public void OnException(ExceptionContext filterContext)   
2.     {  
3.         if (!filterContext.ExceptionHandled && filterContext.E
xception is NullReferenceException)   
4.         {  
5.             filterContext.Result = new RedirectResult("customE
rrorPage.html");  
6.             filterContext.ExceptionHandled = true;  
7.         }  
8.     }  
9. }  

10. What's the difference between @Html.Partial and @Html.RenderPartial


methods?

Html.Partial() Html.RenderParti
Html.Partial returns html string. Html.RenderPartial returns void.
Html.Partial injects the html string of the partial view into the Html.RenderPartial writes html
main view. stream.
Performance is slow. Perform is faster compared with H
Html.Partial() need not to be inside the braces. Html.RenderPartial must be inside
11.

10. How will you override Main layout inheritence for a view?
Using sublayout and renderbody
12. How will you maintain state in a MVC application?
13. Viewbag and viewdata and tempdata
12. ViewBag, ViewState, and TempData - What do these do and when to use what?
ViewData ViewBag TempData
It is Key-Value Dictionary It is Key-Value Dictionary
It is a type object
collection collection
ViewData is a dictionary ViewBag is Dynamic TempData is a dictionary
object and it is property property of ControllerBase object and it is property
of ControllerBase class class. of controllerBase class.
ViewData is Faster than ViewBag is slower than
NA
ViewBag ViewData
TempData is also
ViewData is introduced ViewBag is introduced in
introduced in MVC1.0
in MVC 1.0 and available MVC 3.0 and available in
and available in MVC 1.0
in MVC 1.0 and above MVC 3.0 and above
and above.
ViewData also works ViewBag only works TempData also works
with .net framework 3.5 with .net framework 4.0 and with .net framework 3.5
and above above and above
In depth, ViewBag is used
Type Conversion code is Type Conversion code is
dynamic, so there is no need
required while required while
to type conversion while
enumerating enumerating
enumerating.
Its value becomes null if TempData is used to
redirection has Same as ViewData pass data between two
occurred. consecutive requests.
TempData only works
It lies only during the
Same as ViewData during the current and
current request.
subsequent request

14. What's the use of filters in MVC and what scenarios you can use it? Exception
Handling, Authorization etc. using filters
Inject logic pre or post to an action method execute
15. Bundling and Minification in MVC
 Bundling and minification techniques were introduced in MVC
4 to improve request load time. Bundling allows us to load
the bunch of static files from the server in a single HTTP
request.
 Minification technique optimizes script or CSS file size by
removing unnecessary white space and comments and
shortening variable names to one character.
16. Different types of authentication - Forms, Windows etc. When to use what?
Web applications are3 using forms authentication it comes under the namespace
system.web.security
Using setauthenticate method we can store the user information it sets the
request.isauthenticate to true based on this we can authenticate the users
16. How will you prevent XSS attacks? Hint. HttpAntiForgeryToken
  Using the @Html. AntiforgeryToken()

You might also like