C# Interview Questions

Comparing C# to other languages

  1. Q: What makes C# different than C++?
    A: C# has the CLR. C# has a Garbage collector, Properties, no globals, statics, C# has single inheritance with multiple interfaces while C++ has multiple inheritance. C# allows for the property syntax.
  2. Q: In what ways are C# and C++ the same?
    A: Object oriented. They both have classes, enums, methods, similar types (bool, int, double, etc…).

You can change the above to questions by replacing C++ with any language that candidate may say they are familiar with on their resume: Java, PHP, Ruby, Perl, Python. Of course, you may have to look up the answer. (Or not. You can usually tell by the interviewee’s confidence without knowing the answers yourself.)

C# Basics

Look the basics at least make sure they aren’t completely lying on there resume and they actually have at least done something in C#.

  1. Q: Why is a benefit of having Properties over getters and setters?
    A: If you started using a variable and now you need to wrap code to have multiple actions on get and set, you don’t have to refactor as the Property has the same name and is used the same as a member variable.
    A: Readability. For syntactical purposes the getter and the setter always have to be in the same place in code because they are grouped. Other languages allow for the getter and setter to be anywhere in the object.
  2. Q: What is the syntax for instantiating an instance of each of the following:
    A: bool b = true;
    A: int i = 0;
    real number
    A: double d = 1.0;
    array of integers
    A: int[] myArray = new int[10];
  3. Q: What is the standard way to create an empty string?
    A: string someEmptyValue = string.empty
  4. Q: Is a string mutable or immutable?
    A: immutable.
    Q: What does that mean when performing string manipulation functions?
    A: Any time the string changes, what really happens is a new string is created in a new location in memory.
  5. Q: Write both a for loop and a foreach loop that iterates through a List called myStrings.

    for (int i = 0; i < myStrings.Count; i++)
        // put code here
    foreach  (string str in myStrings)
        // put code here

    Q: Why would you use one method over another?
    A: Maybe you need the current id, so you use the for loop.

C# – Security

  1. Q: What are some security related tools (executable files) included with .NET Framework?
    A: Caspol.exe (Code Access Security Policy Tool): Enables you to view and configure security policy for the machine policy level, the user policy level, and the enterprise policy level. In the .NET Framework 4 and later, this tool does not affect code access security (CAS) policy unless the element is set to true. For more information, see Security Changes in the .NET Framework.Cert2spc.exe (Software Publisher Certificate Test Tool): Creates a Software Publisher’s Certificate (SPC) from one or more X.509 certificates. This tool is for testing purposes only.

    Certmgr.exe (Certificate Manager Tool): Manages certificates, certificate trust lists (CTLs), and certificate revocation lists (CRLs).

    Makecert.exe (Certificate Creation Tool): Generates X.509 certificates for testing purposes only.

    Peverify.exe (PEVerify Tool): Helps you verify whether your Microsoft intermediate language (MSIL) code and associated metadata meet type safety requirements.

    SecAnnotate.exe (.NET Security Annotator Tool): Identifies the SecurityCritical and SecuritySafeCritical portions of an assembly.

    SignTool.exe (Sign Tool): Digitally signs files, verifies signatures in files, and time-stamps files.

    Sn.exe (Strong Name Tool): Helps create assemblies with strong names. This tool provides options for key management, signature generation, and signature verification.

    Ref: http://msdn.microsoft.com/en-us/library/dd233106.aspx

  2. Q: What are some libraries in the System.Security namespace?
    System.Security.RightsManagementQ: Can you discuss any of these libraries?
    A: See what they have to say and compare it to the web site on MSDN for these libraries.

    Q: Which libraries have you used? Tell my about a project you used that library in.

  3. What are some of the Key Security Concepts in C#?
    A: Security Permissions, Type Safety and Security,  Principal, Authentication, Authorization, Security Concerns for Keywords
    Ref: http://msdn.microsoft.com/en-us/library/z164t8hs.aspx
  4. What is Code Access Permissions?
    A: permission objects that are used to help protect resources and operations from unauthorized use. They are a fundamental part of the common language runtime’s mechanism for enforcing security restrictions on managed code.
    Ref: http://msdn.microsoft.com/en-us/library/h846e9b3.aspx

More to come . . .


  1. Damon Hullinger says:


    I like this, thanks for sharing. A suggestion for some addition interview questions might be security related. I'm not a developer but I do talk to developers about security.

    Thanks again, I think it's awesome that you are so proactive about sharing with the community.


Leave a Reply

How to post code in comments?