C# and .NET interview questions
[show/hide]
- How big is the datatype int in .NET? 32 bits.
- How big is the char? 16 bits (Unicode).
- How do you initiate a string without escaping each backslash? Put an @ sign in front of the double-quoted string.
- What are valid signatures for the Main function?
- public static void Main()
- public static int Main()
- public static void Main( string[] args )
- public static int Main(string[] args )
- Does Main() always have to be public? No.
- How do you initialize a two-dimensional array that you don’t know the dimensions of?
- int [, ] myArray; //declaration
- myArray= new int [5, 8]; //actual initialization
- What’s the access level of the visibility type internal? Current assembly.
- What’s the difference between struct and class in C#?
- Structs cannot be inherited.
- Structs are passed by value, not by reference.
- Struct is stored on the stack, not the heap.
- Explain encapsulation. The implementation is hidden, the interface is exposed.
- What data type should you use if you want an 8-bit value that’s signed? sbyte.
- Speaking of Boolean data types, what’s different between C# and C/C++? There’s no conversion between 0 and false, as well as any other number and true, like in C/C++.
- Where are the value-type variables allocated in the computer RAM? Stack.
- Where do the reference-type variables go in the RAM? The references go on the stack, while the objects themselves go on the heap. However, in reality things are more elaborate.
- What is the difference between the value-type variables and reference-type variables in terms of garbage collection? The value-type variables are not garbage-collected, they just fall off the stack when they fall out of scope, the reference-type objects are picked up by GC when their references go null.
- How do you convert a string into an integer in .NET? Int32.Parse(string), Convert.ToInt32()
- How do you box a primitive data type variable? Initialize an object with its value, pass an object, cast it to an object
- Why do you need to box a primitive variable? To pass it by reference or apply a method that an object supports, but primitive doesn’t.
- What’s the difference between Java and .NET garbage collectors? Sun left the implementation of a specific garbage collector up to the JRE developer, so their performance varies widely, depending on whose JRE you’re using. Microsoft standardized on their garbage collection.
- How do you enforce garbage collection in .NET? System.GC.Collect();
- Can you declare a C++ type destructor in C# like ~MyClass()? Yes, but what’s the point, since it will call Finalize(), and Finalize() has no guarantees when the memory will be cleaned up, plus, it introduces additional load on the garbage collector. The only time the finalizer should be implemented, is when you’re dealing with unmanaged code.
- What’s different about namespace declaration when comparing that to package declaration in Java? No semicolon. Package declarations also have to be the first thing within the file, can’t be nested, and affect all classes within the file.
- What’s the difference between const and readonly? You can initialize readonly variables to some runtime values. Let’s say your program uses current date and time as one of the values that won’t change. This way you declare
public readonly string DateT = new DateTime().ToString().
- Can you create enumerated data types in C#? Yes.
- What’s different about switch statements in C# as compared to C++? No fall-throughs allowed.
- What happens when you encounter a continue statement inside the for loop? The code for the rest of the loop is ignored, the control is transferred back to the beginning of the loop.
- Is goto statement supported in C#? How about Java? Gotos are supported in C#to the fullest. In Java goto is a reserved keyword that provides absolutely no functionality.
- Describe the compilation process for .NET code? Source code is compiled and run in the .NET Framework using a two-stage process. First, source code is compiled to Microsoft intermediate language (MSIL) code using a .NET Framework-compatible compiler, such as that for Visual Basic .NET or Visual C#. Second, MSIL code is compiled to native code.
- Name any 2 of the 4 .NET authentification methods. ASP.NET, in conjunction with Microsoft Internet Information Services (IIS), can authenticate user credentials such as names and passwords using any of the following authentication methods:
- Windows: Basic, digest, or Integrated Windows Authentication (NTLM or Kerberos).
- Microsoft Passport authentication
- Forms authentication
- Client Certificate authentication
- How do you turn off SessionState in the web.config file? In the system.web section of web.config, you should locate the httpmodule tag and you simply disable session by doing a remove tag with attribute name set to session.
- What is main difference between Global.asax and Web.Config? ASP.NET uses the global.asax to establish any global objects that your Web application uses. The .asax extension denotes an application file rather than .aspx for a page file. Each ASP.NET application can contain at most one global.asax file. The file is compiled on the first page hit to your Web application. ASP.NET is also configured so that any attempts to browse to the global.asax page directly are rejected. However, you can specify application-wide settings in the web.config file. The web.config is an XML-formatted text file that resides in the Web site’s root directory. Through Web.config you can specify settings like custom 404 error pages, authentication and authorization settings for the Web site, compilation options for the ASP.NET Web pages, if tracing should be enabled, etc.
没有评论:
发表评论