C# Interview Questions 2

By | April 28, 2014

Can DateTime variables be null?
A1: No, because it is a value type (Struct)

Q2: Describe the Asp.net Page Life Cycle?
A2: http://msdn2.microsoft.com/en-us/library/ms178472.aspx

Q3: Describe the Asp.net pipeline ? Give an Example when you need to extend it? How do you do so?
A3: http://msdn.microsoft.com/msdnmag/issues/02/09/HTTPPipelines/

Q4: Describe the accessibility modifier protected internal
A4: Members are accessible to derived classes and classes within the same Assembly

Q5: Difference between an interface and abstract class?
A5: In the interface all methods must be abstract, in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

Q6: How do you perform pre- and post-processing to extend a WebMethod ?
A6: Use SOAP extensions …http://msdn.microsoft.com/msdnmag/issues/04/03/ASPColumn/

Q7: What are Design Patterns?
A7: It is a big topic in Object Oriented, so for more information see this, http://dofactory.com/Patterns/Patterns.aspx

Q8: What do you know about .net framework 3.0 ?
A8: any answer that introduces Windows Communication Foundation (WCF), Windows Workflow Foundation (WF), Windows Presentation Foundation (WPF) and Windows Card Space (WCS) is right, also you can mention that it was originally called WinFX

Q9: What do you know about ATLAS (Microsoft ASP.net AJAX Extensions) ?
A9: for more information check here, http://ajax.asp.net

Q10: What do you know about Agile software methodologies?
A10: http://en.wikipedia.org/wiki/Agile_software_development

Q11: What do you know about Web Services Enhancements (WSE)?
A11: http://msdn.microsoft.com/webservices/webservices/building/wse/default.aspx

Q12: What is AJAX ?
A12: Asynchronous Javascript And XML

Q13:What is NUnit, or What is Unit testing?
A13: Unit testing: is a procedure used to validate that a particular module of source code is working properly from each modification to the next. The procedure is to write test cases for all functions and methods so that whenever a change causes a regression, it can be quickly identified and fixed. Ideally, each test case is separate from the others; constructs such as mock objects can assist in separating unit tests. This type of testing is mostly done by the developers, NUnit is a famous tool for Unit Testing in .net

Q14: What is an Asp.net Http Handler & Http Module?
A14: http://www.15seconds.com/issue/020417.htm

Q15: What is mutable type ? immutable type ?
A15: Immutable type are types whose instance data, fields and properties, does not change after the instance is created. Most value types are immutable, but the mutable type are A type whose instance data, fields and properties, can be changed after the instance is created. Most Reference Types are mutable.

Q16: What is the HttpContext Object? Where is it accessible?
A16: It’s is an Object that Encapsulates all HTTP-specific information about an individual HTTP request. it is avaliable through out the Asp.net request pipline.

Q17: What is the difference between String & StringBuilder classes?
A17: String is an immutable type while StringBuilder is a mutable type

Q18: What’s the difference between C# 1.0 & C# 2.0?
A18: Any answer that introduces stuff like, Generics, Anonymous Methods, Nullable types, Iterators … etc, is correct

Q19: Without using the multiplication or addition operations, how can you multiply a number x by 8?
A19: Shift x to the left 3 times, x << 3, because every shift left multiplies the number by 2

Q20: What is the difference between ASP.net 1.x & ASP.net 2.0 ?
A20: Any answer that include stuff like Provider model (membership provider, role provider … etc) and Master Pages, Code Beside model, new web controls will be ok. If you have more questions feel free to join the user group and add them directly to the database.

Can DateTime variables be null?
A1: No, because it is a value type (Struct)

Q2: Describe the Asp.net Page Life Cycle?
A2: http://msdn2.microsoft.com/en-us/library/ms178472.aspx

Q3: Describe the Asp.net pipeline ? Give an Example when you need to extend it? How do you do so?
A3: http://msdn.microsoft.com/msdnmag/issues/02/09/HTTPPipelines/

Q4: Describe the accessibility modifier protected internal
A4: Members are accessible to derived classes and classes within the same Assembly

Q5: Difference between an interface and abstract class?
A5: In the interface all methods must be abstract, in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

Q6: How do you perform pre- and post-processing to extend a WebMethod ?
A6: Use SOAP extensions …http://msdn.microsoft.com/msdnmag/issues/04/03/ASPColumn/

Q7: What are Design Patterns?
A7: It is a big topic in Object Oriented, so for more information see this, http://dofactory.com/Patterns/Patterns.aspx

Q8: What do you know about .net framework 3.0 ?
A8: any answer that introduces Windows Communication Foundation (WCF), Windows Workflow Foundation (WF), Windows Presentation Foundation (WPF) and Windows Card Space (WCS) is right, also you can mention that it was originally called WinFX

Q9: What do you know about ATLAS (Microsoft ASP.net AJAX Extensions) ?
A9: for more information check here, http://ajax.asp.net

Q10: What do you know about Agile software methodologies?
A10: http://en.wikipedia.org/wiki/Agile_software_development

Q11: What do you know about Web Services Enhancements (WSE)?
A11: http://msdn.microsoft.com/webservices/webservices/building/wse/default.aspx

Q12: What is AJAX ?
A12: Asynchronous Javascript And XML

Q13:What is NUnit, or What is Unit testing?
A13: Unit testing: is a procedure used to validate that a particular module of source code is working properly from each modification to the next. The procedure is to write test cases for all functions and methods so that whenever a change causes a regression, it can be quickly identified and fixed. Ideally, each test case is separate from the others; constructs such as mock objects can assist in separating unit tests. This type of testing is mostly done by the developers, NUnit is a famous tool for Unit Testing in .net

Q14: What is an Asp.net Http Handler & Http Module?
A14: http://www.15seconds.com/issue/020417.htm

Q15: What is mutable type ? immutable type ?
A15: Immutable type are types whose instance data, fields and properties, does not change after the instance is created. Most value types are immutable, but the mutable type are A type whose instance data, fields and properties, can be changed after the instance is created. Most Reference Types are mutable.

Q16: What is the HttpContext Object? Where is it accessible?
A16: It’s is an Object that Encapsulates all HTTP-specific information about an individual HTTP request. it is avaliable through out the Asp.net request pipline.

Q17: What is the difference between String & StringBuilder classes?
A17: String is an immutable type while StringBuilder is a mutable type

Q18: What’s the difference between C# 1.0 & C# 2.0?
A18: Any answer that introduces stuff like, Generics, Anonymous Methods, Nullable types, Iterators … etc, is correct

Q19: Without using the multiplication or addition operations, how can you multiply a number x by 8?
A19: Shift x to the left 3 times, x << 3, because every shift left multiplies the number by 2

Q20: What is the difference between ASP.net 1.x & ASP.net 2.0 ?
A20: Any answer that include stuff like Provider model (membership provider, role provider … etc) and Master Pages, Code Beside model, new web controls will be ok.

=================================================================================================

1. What are you thoughts on the following?
: try { … } catch (Exception ex) { … } The answer should create an insight into how deeply the developer thinks. I think catch all exceptions are the devils spawn, but would be interested in learning justification someone might have for using

2. Name your favourite feature of .NET 2.0? Why? Just a matter of interest. Should get the person talking.

3. Explain the difference between an Interface, and an Abstract class. If the person knows the difference then it shows they have created bases classes or at least know about OO programming.

4. In your opinion, when should you use each? Just to try and see if they have an understanding of the difference, not just know what each is.

5. How do you define the n-tier model? Again it should be reasonably clear from the answer if the person has actually don e n-tier design/programming

6. When passing data between tiers, do you prefer passing a custom class, or something else such as a Dataset? Why? Always interesting to hear peoples approach to this. Also it demonstrates what level the person has. I.E a junior – intermediate may not have had to worry about this before.

7. Who is Anders Hjelsberg? I would want people who take an interest in the language they use. If they do then they will know who Anders is, or at least heard of him

8. Explain the terms Pascal Casing and Camel Casing. Most people should know what these mean, although not a show stopper if not

9. Explain your coding standards for: a member variable, a parameter, a method, a class an interface and a local variable. This question just shows if people have thought about standards or not. Any good developer should have a fixed standard they stick to. It is good to discuss their reasonings for using a particular standard. For example I use m_(camelCase) for member variables because I feel it is easier to read and harder to transpose the variable by mistake.

10. What is your understanding of a business layer? Everyone has a different idea about what a Business Layer should be and do. Coding Tasks Here are some coding tasks that could be given at an interview. Obviously not enough time to do them all….

1. You are creating a basic accounting application. Create a business layer stub which would allow the application handle Creditors, Debtors and Invoices. Just create any classes needed, the variables needed and the method headers. In each method, just add a comment as to what the method will do. As a starting point, the database has been created where the business data will be persisted to. I think this would be an interesting task to give. It shows the interviewee’s ability to take a problem and apply their skills to it. We’re not really that interested in the actual coding, just the design and thinking behind it. I would expect most people to either create custom classes based on the database, or create an approach based on datasets which will be passed between layers. I am a student of the Rocky Lhotka approach to business layers where the business classes shouldn’t just replicate the table design, it should define a behaviour, and can include data from several tables.

2. Create a simple Webservice that given two numbers, returns the sum of these two numbers.

3. Create a console application that consumes the Webservice created above. Fairly simple task that anyone worth hiring should handle in 30 minutes or so.

4. Give them an application with a number of bugs, some compile time, some runtime and get them to fix as many as possible in a given time.

5. Explain to the interviewee that they can use any datastore they like – have MS Access, SQL Express, SQL Server installed on the test machine – create a simple application to store contact details

=================================================================================================

  1. Is it possible to inline assembly or IL in C# code? – No.
  2. Is it possible to have different access modifiers on the get/set methods of a property? – No. The access modifier on a property applies to both its get and set accessors. What you need to do if you want them to be different is make the property read-only (by only providing a get accessor) and create a private/internal set method that is separate from the property.
  3. Is it possible to have a static indexer in C#? – No. Static indexers are not allowed in C#.
  4. If I return out of a try/finally in C#, does the code in the finally-clause run? – Yes. The code in the finally always runs. If you return out of the try block, or even if you do a “goto” out of the try, the finally block always runs:
    using System; class main { public static void Main() { try { Console.WriteLine(\"In Try block\"); return; } finally { Console.WriteLine(\"In Finally block\"); } } }
    
    

    Both “In Try block” and “In Finally block” will be displayed. Whether the return is in the try block or after the try-finally block, performance is not affected either way. The compiler treats it as if the return were outside the try block anyway. If it’s a return without an expression (as it is above), the IL emitted is identical whether the return is inside or outside of the try. If the return has an expression, there’s an extra store/load of the value of the expression (since it has to be computed within the try block).

  5. I was trying to use an “out int” parameter in one of my functions. How should I declare the variable that I am passing to it? – You should declare the variable as an int, but when you pass it in you must specify it as ‘out’, like the following: int i; foo(out i); where foo is declared as follows: [return-type] foo(out int o) { }
  6. How does one compare strings in C#? – In the past, you had to call .ToString() on the strings when using the == or != operators to compare the strings’ values. That will still work, but the C# compiler now automatically compares the values instead of the references when the == or != operators are used on string types. If you actually do want to compare references, it can be done as follows: if ((object) str1 == (object) str2) { … } Here’s an example showing how string compares work:
    using System; public class StringTest { public static void Main(string[] args) { Object nullObj = null; Object realObj = new StringTest(); int i = 10; Console.WriteLine(\"Null Object is [\" + nullObj + \"]\n\" + \"Real Object is [\" + realObj + \"]\n\" + \"i is [\" + i + \"]\n\"); // Show string equality operators string str1 = \"foo\"; string str2 = \"bar\"; string str3 = \"bar\"; Console.WriteLine(\"{0} == {1} ? {2}\", str1, str2, str1 == str2 ); Console.WriteLine(\"{0} == {1} ? {2}\", str2, str3, str2 == str3 ); } }

    Output:

    Null Object is [] Real Object is [StringTest] i is [10] foo == bar ? False bar == bar ? True
  7. How do you specify a custom attribute for the entire assembly (rather than for a class)? – Global attributes must appear after any top-level using clauses and before the first type or namespace declarations. An example of this is as follows:
    using System; [assembly : MyAttributeClass] class X {}

    Note that in an IDE-created project, by convention, these attributes are placed in AssemblyInfo.cs.

  8. How do you mark a method obsolete?
    [Obsolete] public int Foo() {...}

    or

    [Obsolete(\"This is a message describing why this method is obsolete\")] public int Foo() {...}

    Note: The O in Obsolete is always capitalized.

  9. How do you implement thread synchronization (Object.Wait, Notify,and CriticalSection) in C#? – You want the lock statement, which is the same as Monitor Enter/Exit:
    lock(obj) { // code }

    translates to

    try { CriticalSection.Enter(obj); // code } finally { CriticalSection.Exit(obj); }
  10. How do you directly call a native function exported from a DLL? – Here’s a quick example of the DllImport attribute in action:
    using System.Runtime.InteropServices; \ class C { [DllImport(\"user32.dll\")] public static extern int MessageBoxA(int h, string m, string c, int type); public static int Main() { return MessageBoxA(0, \"Hello World!\", \"Caption\", 0); } }

    This example shows the minimum requirements for declaring a C# method that is implemented in a native DLL. The method C.MessageBoxA() is declared with the static and external modifiers, and has the DllImport attribute, which tells the compiler that the implementation comes from the user32.dll, using the default name of MessageBoxA. For more information, look at the Platform Invoke tutorial in the documentation.

  11. How do I simulate optional parameters to COM calls? – You must use the Missing class and pass Missing.Value (in System.Reflection) for any values that have optional parameters.

^Back to Top

C# developer interview questions

A representative of a high-tech company in United Kingdom sent this in today noting that the list was used for interviewing a C# .NET developer. Any corrections and suggestions would be forwarded to the author. I won’t disclose the name of the company, since as far as I know they might still be using this test for prospective employees. Correct answers are in green color.

1) The C# keyword .int. maps to which .NET type?

  1. System.Int16

  2. System.Int32

  3. System.Int64

  4. System.Int128

2) Which of these string definitions will prevent escaping on backslashes in C#?

  1. string s = #.n Test string.;

  2. string s = ..n Test string.;

  3. string s = @.n Test string.;

  4. string s = .n Test string.;

3) Which of these statements correctly declares a two-dimensional array in C#?

  1. int[,] myArray;

  2. int[][] myArray;

  3. int[2] myArray;

  4. System.Array[2] myArray;

4) If a method is marked as protected internal who can access it?

  1. Classes that are both in the same assembly and derived from the declaring class.

  2. Only methods that are in the same class as the method in question.

  3. Internal methods can be only be called using reflection.

  4. Classes within the same assembly, and classes derived from the declaring class.

5) What is boxing?

a) Encapsulating an object in a value type.

b) Encapsulating a copy of an object in a value type.

c) Encapsulating a value type in an object.

d) Encapsulating a copy of a value type in an object.

6) What compiler switch creates an xml file from the xml comments in the files in an assembly?

  1. /text

  2. /doc

  3. /xml

  4. /help

7) What is a satellite Assembly?

  1. A peripheral assembly designed to monitor permissions requests from an application.

  2. Any DLL file used by an EXE file.

  3. An assembly containing localized resources for another assembly.

  4. An assembly designed to alter the appearance or .skin. of an application.

8) What is a delegate?

  1. A strongly typed function pointer.

  2. A light weight thread or process that can call a single method.

  3. A reference to an object in a different process.

  4. An inter-process message channel.

9) How does assembly versioning in .NET prevent DLL Hell?

  1. The runtime checks to see that only one version of an assembly is on the machine at any one time.

  2. .NET allows assemblies to specify the name AND the version of any assemblies they need to run.

  3. The compiler offers compile time checking for backward compatibility.

  4. It doesn.t.

10) Which .Gang of Four. design pattern is shown below?

public class A {

    private A instance;

    private A() {

    }

    public static A Instance {

        get

        {

            if ( A == null )

                A = new A();

            return instance;

        }

    }

}

  1. Factory

  2. Abstract Factory

  3. Singleton

  4. Builder

11) In the NUnit test framework, which attribute must adorn a test class in order for it to be picked up by the NUnit GUI?

  1. TestAttribute

  2. TestClassAttribute

  3. TestFixtureAttribute

  4. NUnitTestClassAttribute

12) Which of the following operations can you NOT perform on an ADO.NET DataSet?

  1. A DataSet can be synchronised with the database.

  2. A DataSet can be synchronised with a RecordSet.

  3. A DataSet can be converted to XML.

  4. You can infer the schema from a DataSet.

13) In Object Oriented Programming, how would you describe encapsulation?

  1. The conversion of one type of object to another.

  2. The runtime resolution of method calls.

  3. The exposition of data.

  4. The separation of interface and implementation.

====================================================================================================

1 Describe the difference between a Thread and a Process?

2 What is a Windows Service and how does its lifecycle differ from a “standard” EXE?

3 What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?

4 What is the difference between an EXE and a DLL?

5 What is strong-typing versus weak-typing? Which is preferred? Why?

6 Corillian’s product is a “Component Container.” Name at least 3 component containers that ship now with the Windows Server Family.

7 What is a PID? How is it useful when troubleshooting a system?

8 How many processes can listen on a single TCP/IP port?

9 What is the GAC? What problem does it solve?

10 What is serialization in .NET? What are the ways to control serialization?

11 Does C# support multiple inheritance?

12 What’s the implicit name of the parameter that gets passed into the class’ set method?

13 What’s the top .NET class that everything is derived from?

14 How’s method overriding different from overloading?

15 What is CLR?

16 What is CTS?

17 What is CLS?

18 What is strong name?

19 What is Application Domain?

20 Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming.

21 Describe what an Interface is and how it’s different from a Class.

22 What is Reflection?

23 What is the difference between XML Web Services using ASMX and .NET Remoting using SOAP?

24 Are the type system represented by XmlSchema and the CLS isomorphic?

25 Conceptually, what is the difference between early-binding and late-binding?

26 Is using Assembly.Load a static reference or dynamic reference?

27 When would using Assembly.LoadFrom or Assembly.LoadFile be appropriate?

28 What is an Asssembly Qualified Name? Is it a filename? How is it different?

29 Is this valid? Assembly.Load(“foo.dll”);

30 How is a strongly-named assembly different from one that isn’t strongly-named?

31 Can DateTimes be null?

32 What is the JIT? What is NGEN? What are limitations and benefits of each?

33 How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization?

34 What is the difference between Finalize() and Dispose()?

35 How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?

36 What does this useful command line do? tasklist /m “mscor*”

37 What is the difference between in-proc and out-of-proc?

38 What technology enables out-of-proc communication in .NET?

39 When you’re running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?

40 What is FullTrust? Do GAC’ed assemblies have FullTrust?

41 What are Satellite Assemblies?

42 What is Global Assembly Cache (GAC) and what is the purpose of it?

43 What is Reflection in .NET?

44 What is the managed and unmanaged code in .net?

45 What are Namespaces?

46 What are the access-specifiers available in c#?

47 Advantage of ADO.Net?

48 Difference between OLEDB Provider and SqlClient ?

49 Differences between dataset.clone and dataset.copy?

50 In a Webservice, need to display 10 rows from a table. So DataReader or DataSet is best choice?

51 What is Remoting?

52 What’s the difference between System.String and System.StringBuilder classes?

53 What’s a delegate?

54 What’s an interface class?

55 What is the transport protocol you use to call a Web service ?

56 What’s wrong with a line like this? DateTime.Parse(myString);

57 What are PDBs? Where must they be located for debugging to work?

58 What is cyclomatic complexity and why is it important?

59 Write a standard lock() plus “double check” to create a critical section around a variable access.

60 What benefit does your code receive if you decorate it with attributes demanding specific Security permissions?

61 What does this do? gacutil /l | find /i “Corillian”

62 What does this do? sn -t foo.dll

63 What ports must be open for DCOM over

Leave a Reply