• Home
  • Trace mobile number (From India)
  • Entertainment
  • SiteMap
  • Home
  • ASP.NET
  • C#
  • BLOGGING
  • SQL SERVER
  • FACEBOOK
  • Entertainment
Showing posts with label C# Interview Questions. Show all posts
Difference between MVC2, MVC3 and MVC4 

View Engine : 
·         View Engine is responsible for rendering of the HTML code from your views to the browser.
·         MVC 2 uses only Web Forms view engine (.aspx) as a default View Engine.
·         MVC3 uses Razor View Engine (.cshtml for c# and .vbhtml for Visual Basic) and Web Forms view engine (.aspx).
·         MVC4 also uses Razor View Engine as a default view engine with some new features like condition attribute and ‘Tilde slash’.

Chart, WebGrid, Crypto,WebImage, WebMail Controls : 
·         All these are not available in MVC2.
·         All these are available in MVC3 and in MVC4.

Syntex : 
·         (HTML Syntax) Web Forms view engine syntax: <%=Html code %> in MVC2.
·         (Razor Syntax) Razor View Engine syntax: @Html code in MVC3.
·         MVC4 has the same Razor View Engine Syntax but with the addition of new features like conditional attribute and ‘Tilde Slash’ i.e. URL resolution.

Objects available for sharing of data between View and Controller : 
·         TempData, ViewData are available in MVC2.
·         TempData, ViewData ,ViewBag are available in MVC3.
·         TempData, ViewData ,ViewBag are available in MVC4.
·         TempData is used with current and subsequent request i.e. when you know the next view to be redirected.
·         In ViewData, dictionary of objects are accessible via strings as keys.
·         ViewBag was added in the C# 4.0 which uses the dynamic feature that allows to add properties of an object dynamically . We can say that ViewBag = ViewData + dynamic feature around the ViewData dictionary.

Jquery Support : 
·         Jquery support is Good in MVC2.
·         Jquery support is Better in MVC3.
·         MVC4 provides better support for Jquery like Jquery Mobile.

Dependency Injection Support : 
·         Dependency injection is Good in MVC2.
·         It provides powerful hooks with Dependency Injection and Global Action Filters in MVC3.
·         Better support in MVC4.

Layout Support : 
·         Supports only Master Page in MVC2.
·         Supports not only Master Page but also Layout Page in MVC 3 and in MVC4.

Validation : 
·         Client-side Validation and Asynchronous controllers is there in MVC2.
·         Unobtrusive Ajax and Client side Validation, Jquery Validation and JSON binding support is in MVC3.
·         Client side validation, Jquery validation and enhanced support for asynchronous methods in MVC4.

Project Templates : 
·         MVC3 supports project templates enabled by HTML 5.
·         MVC4 supports many new features for mobile apps and also provides new mobile project template and default templates are refreshed and modernized.


Is using try catch is good experience in coding practice here is a detailed answer .

Best practice is that exception handling should never hide issues. This means that try-catch blocks should be extremely rare.

There are 3 circumstances were using a try-catch makes sense.

1. Always deal with known exceptions as low-down as you can. However, if you're expecting an exception it's usually better practice to test for it first. For instance parse, formatting and arithmetic exceptions are nearly always better handled by logic checks first, rather than a specific try-catch.

2. If you need to do something on an exception (for instance logging or roll back a transaction) then re-throw the exception.


3. Always deal with unknown exceptions as high-up as you can - the only code that should consume an exception and not re-throw it should be the UI or public API.
Below is the use of JIT.

1. JIT is a compiler which converts MSIL code to Native Code (ie.. CPU-specific code that runs on the same computer architecture).

2. Because the common language runtime supplies a JIT compiler for each supported CPU architecture, developers can write a set of MSIL that can be JIT-compiled and run on computers with different architectures.

3. However, your managed code will run only on a specific operating system if it calls platform-specific native APIs, or a platform-specific class library.

4. JIT compilation takes into account the fact that some code might never get called during execution.

5. Rather than using time and memory to convert all the MSIL in a portable executable (PE) file to native code, it converts the MSIL as needed during execution and stores the resulting native code so that it is accessible for subsequent calls.

6. The loader creates and attaches a stub to each of a type's methods when the type is loaded.

7. On the initial call to the method, the stub passes control to the JIT compiler, which converts the MSIL for that method into native code and modifies the stub to direct execution to the location of the native code.

8. Subsequent calls of the JIT-compiled method proceed directly to the native code that was previously generated, reducing the time it takes to JIT-compile and run the code.
1. GUID is Short form of Globally Unique Identifier, a unique 128-bit number that is produced by the Windows OS or by some Windows applications to identify a particular component, application, file, database entry, and/or user.

2. For instance, a Web site may generate a GUID and assign it to a user's browser to record and track the session.

3. A GUID is also used in a Windows registry to identify COM DLLs.

4. Knowing where to look in the registry and having the correct GUID yields a lot information about a COM object (i.e., information in the type library, its physical location, etc.).

5. Windows also identifies user accounts by a username (computer/domain and username) and assigns it a GUID.

6. Some database administrators even will use GUIDs as primary key values in databases.

7. GUIDs can be created in a number of ways, but usually they are a combination of a few unique settings based on specific point in time (e.g., an
IP address, network MAC address, clock date/time, etc.).

Here i am showing how to create a GUID in c#?

Guid id = Guid.NewGuid();

Console.WriteLine(id); // Outputs "8c1d1c4b-df68-454c-bf30-953e5701949f"


Here is list of oops interview questions and answers for freshers and experienced from basic to advance Object Oriented Programming questions with examples . Net Interview Questions and Answers | OOPs Interview Questions with Answers PDF | OOPs Interview Questions in C++ c# .

Frequently asked .Net Interview Questions and Answers on Object Oriented Programming (OOPS) .NET Interview Questions and answers on OOPS.Here is List of questions.Frequently Asked Questions with answers.


  1. What is Abstract method?
  2. What is Polymorphisms?
  3. What is Virtual method?
  4. Can Struct be inherited?
  5. What is Object?
  6. What is Class?
  7. What is Static field?
  8. What is Static Method?
  9. What is Inheritance?
  10. What is Virtual keyword?
  11. What is New modifiers?
  12. What is Abstract Class?
  13. What is Sealed modifiers?
  14. What is an Interface?
  15. When to use Interface over abstract class?
  16. What is pure virtual function?
  17. Can we specify the access modifier for explicitly implemented interface method?
  18. What is Protected access modifier in C#?
  19. What is Public access modifier in C#?
  20. What is Private access modifier in C#?
  21. What is Internal access modifier in C#?
  22. What is Protected Internal access modifier in C#?
  23. What is method overloading?
  24. What is Overriding?
  25. What is Method overloading?
  26. What is Method Overriding? How to override a function in C#?
  27. Can we call a base class method without creating instance?
  28. In which cases you use override and new base?
  29. Difference between new and override keyword?
  30. What is a private constructor? Where will you use it?
  31. Can we declare private class in a Namespace?
  32. What is Polymorphism?
  33. What Are Attributes in DotNet?

  34. What can you do to make class available for inheritance but you need to prevent it's method to come in inheritance chain?
  35. What's the Difference between Interface and Abstract Class
  36. What are the various types of Constructors
  37. What are Constructors ?
  38. When to Use Abstract Classes and When Interfaces.
  39. Diversities between an abstract method & virtual method ?
  40. What is Early binding and late binding?
  41. How's method overriding different from overloading?
  42. What does the keyword virtual mean in the method definition?
  43. Can you declare the override method static while the original method is non-static?
  44. Can you override private virtual methods?
  45. Can you prevent your class from being inherited and becoming a base class for some other classes?
  46. Can you allow class to be inherited, but prevent the method from being over-ridden?
  47. Why can't you specify the accessibility modifier for methods inside the interface?
  48. Static datamembers should be initialized inside the constructor. True or False.
  49. Static methods can not use non static members. True or False.
  50. A constructor can be private. True or False?
  51. What is the work of a constructor?
  52. Name the operators that cannot be overloaded.
  53. What is "this" pointer?
  54. Difference between sealed and static classes.
  55. Differences between a structure and class.
  56. What are the different ways a method can be overloaded?
  57. Difference between a Class and an object.
  58. Define OOPS. What are its benefits?
  59. Can we have Sealed Method in abstarct class ?
  60. Can we have an Abstract class without having any abstract method ??
  61. Can we have Multiple Main Methods in one .cs file
  62. If the Function has same parameter but different return type (int and float), Is it a overloading?
  63. How does Composition mechanism works ?
  64. What is the advantage of parametric polymorphism ?
  65. What is difference in between abstrct classes and interfaces ?
  66. Overloading is Static Polymorphism and Overriding is Dynamic Polymorphism ? True or False ?
  67. What is the default access modifier of a class?
  68. Can a constructors that is declared within a base class, inherited by subclasses ? Yes or No


Often we need to capitalize the first letters of some word or some text (for example when we want to display users name or city name etc).

Since string class does not have a method to do this we could think that there is no built-in solution in C# for this problem.

Here i am giving two solution for this problem.

Solution 1-

We can use  ToTitleCase method of TextInfo class in System.Globalization namespace  for this problem.

    public static string Capitalize(string value)
    {
        return       System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value);
    }

Solution 2-

The below method will return  Capitalize Words.

   public static string CapitalizeWords(string value)
    {
        if (value == null)
            throw new ArgumentNullException("value");
        if (value.Length == 0)
            return value;

        StringBuilder result = new StringBuilder(value);
        result[0] = char.ToUpper(result[0]);
        for (int i = 1; i < result.Length; ++i)
        {
            if (char.IsWhiteSpace(result[i - 1]))
                result[i] = char.ToUpper(result[i]);
        }
        return result.ToString();
    }

When we  thinking how to solve this is problem  JavaScript comes in our mind And off course, that IS THE WAY TO GO.

ASP.NET 2.0 introduced DefaultFocus and DefaultButton properties for HtmlForm class that you can easily use for requirements like this.


DefaultFocus property gets or sets the child control on the HtmlForm that will receive the focus when the HtmlForm is loaded.

DefaultButton property gets or sets the child control of the HtmlForm that causes postback when enter key is pressed on the page.

Here is an example on how to use this two properties in your pages:

  <form id="formtest" runat="server" defaultfocus="txtfirstname" 
 defaultbutton="btnsubmit ">
    <div>
        Name:
        <asp:TextBox ID="txtfirstname btnsubmit" runat="server"></asp:TextBox><br />
        Address:
        <asp:TextBox ID="txtadress" runat="server"></asp:TextBox><br />       
        <asp:Button ID="btnsubmit" runat="server" Text="Submit" />&nbsp;       
        <asp:Button ID="btnsubmit" runat="server" Text="Cancel" />               
    </div>
    </form>

NOte: In order for this to work, your form must have runat="server" attribute set.
Implicit type conversion


In Implicit type conversion one datatype is automatically converted to other datatype by compliler.





    using System;

    class ConversionTest
{
    public static void Main()
    {
        byte mybyte = 1;
        int myintA = 1234;
        int myintB = mybyte; // this will Implicit cast from byte to int datatypes.
        double DoubleD = myintA; // this is Implicit cast from int  to double datatype.
        Console.WriteLine("{0}", myintB);
        Console.WriteLine("{0}", DoubleD);
    }
}

Explicit type conversion

In explicit type conversion the type conversion  is explicitly defined within a program it is not done by compiler Implicitly.


    double A = 101.2;
    double B = 305.3;
    double C = 306.4;
    int result = (int)A + (int)B + (int)C; //result == 712


A regular expression known as regex in short  is a special text string which describes  a search pattern.

Here is a c# function which accept  a string as input parameter and return true if string is valid Email address  and  return  false if string is not valid .

For this function to work properly you have to add these namespaces.


using System.Text;
using System.Text.RegularExpressions;



   protected bool checkEmail(string Emailtext)

    {

     Regex MyEmailRegex = new Regex(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");

     if (string.IsNullOrEmpty(Emailtext))

     {

         return false;

     }

     else

     {

         return MyEmailRegex.IsMatch(Emailtext);

     }

   }

By using this function you can check that Email format is a valid email format or not on server side.in my next article I will explain how you can check for email format using javascript.
Structs are the userdefined data type. Structs are defined by using the struct keyword in c#.

for example:
public struct StructA
{
public int x, y;

public A(int p1, int p2)
{
x = p1;
y = p2;
}
}


It is an error to define a default (parameterless) constructor for a struct. It is also an error to initialize an instance field in a struct body. You can initialize struct members only by using a parameterized constructor or by accessing the members individually after the struct is declared.

This example demonstrates struct initialization using both default and parameterized constructors.

public struct StructA
{
public int x, y;

public StructA (int p1, int p2)
{
x = p1;
y = p2;
}
}

class TestStructA
{
static void Main()
{
// Initialize:
StructA StructA1 = new StructA();
StructA StructA2 = new StructA(10, 10);

// Display results:
Console.Write("StructA 1: ");
Console.WriteLine("x = {0}, y = {1}", StructA1.x, StructA1.y);

Console.Write("StructA 2: ");
Console.WriteLine("x = {0}, y = {1}", StructA2.x, StructA2.y);

// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}

Structs Almost have same syntax as classes, But structs are more limited than classes:

• Within a struct declaration, fields cannot be initialized unless they are declared as const or static.

• A struct cannot declare a default constructor (a constructor without parameters) or a destructor.

• Structs are copied on assignment. When a struct is assigned to a new variable, all the data is copied, and any modification to the new copy does not change the data for the original copy.

• Structs are value types but classes are reference types.

• structs can be instantiated without using a new operator.

• Structs can declare constructors that have parameters.

• A struct cannot support the inheritance.

• All structs inherit directly from System.ValueType, which inherits from System.Object.

• A struct can implement interfaces.

• A struct can be used as a nullable type and can be assigned a null value.
Older Posts Home

Most Read

  • How to Capitalize the First Letter of All Words in a string in C# ?
  • keyboard shortcuts For Windows
  • List Of Best Free WordPress Plugins : 2012
  • Read Write XML Data-Read Write XML File Using C#, VB.NET In Asp.Net
  • How to Shake Internet Explorer - Javascript Code
  • How to Choose a Nice Topic for your Blog .
  • Free Search Engine Submission List ,search engine optimization
  • Number validation in Textbox of ASP.NET Using Regular Expression validator
  • Javascript:Percentage Gain Javascript Calculator
  • .Net Interview Questions and Answers on OOPS | OOPS Frequently Asked Questions
Google
Custom Search Bloggers - Meet Millions of Bloggers

Join Us On FaceBook

  • Recent Posts
  • Comments

All Topics

  • ▼  2014 (10)
    • ▼  January (10)
      • ASP.NET Interview Question : difference between ge...
      • Dot Net Framework:What is the .NET Framework?
      • Dot NET Framework - .NET Framework Interview Quest...
      • What is the differences between MVC2,MVC3 and MVC4...
      • Is try catch is using a good coding (exception han...
      • What is the use of Just - In - Time (JIT)?
      • What is GUID , why we use it?,how to create a GUID
      • How to Rename database table column in sqlserver
      • How to Rename Database in sqlserver
      • Asp.net Example Calendar Control
  • ►  2013 (14)
    • ►  October (1)
    • ►  April (2)
    • ►  March (11)
  • ►  2012 (142)
    • ►  December (25)
    • ►  October (1)
    • ►  September (9)
    • ►  August (2)
    • ►  July (7)
    • ►  June (2)
    • ►  April (5)
    • ►  March (27)
    • ►  February (27)
    • ►  January (37)
  • ►  2011 (23)
    • ►  December (3)
    • ►  November (6)
    • ►  October (12)
    • ►  September (2)
  • ►  2009 (1)
    • ►  June (1)

Tips & Tricks

  • What is good One Blog and Many Categories, or Many Blogs with One Categories?
  • Adding Twitter tweet button to each Blogger posts.
  • How to Choose a Nice Topic for your Blog .
  • Embedding YouTube Videos ,movie in your blog
  • Facebook iFrame Apps – Getting Rid of Scrollbars
  • Facebook Analytics:How to Set Up Your Website or Blog with Facebook Insights for Domains
  • How To Add Perfect Share Box to Blogger
  • Blogger Free Images Hosting Tip,Free unlimited bandwidth image hosting for Blogger blogs
  • Add “Link to this post” codes below Each blogger posts
  • Free Search Engine Submission List ,search engine optimization
  • Adsense Tips for Maximum CTR
  • List Of Best Free WordPress Plugins : 2012
2012 tectopix. All rights reserved.
Designed by tectopix