Competitive Examinations, Scholarships

Interview questions for C# developers

Filed under:

Interview questions for C# developers

Useful for preparation, but too specific to be used in the interview.
Is it possible to inline assembly or IL in C# code? - No.

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.

Is it possible to have a static indexer in C#? - No. Static indexers are not allowed in C#.

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).

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) { }

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

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.
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.

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);
}

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.

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.

Related pages

Interview questions for Web application developers

Interview questions for Web application developers What is the maximum length of a varchar field in SQL Server? How do you define an integer in SQL Server? How do you separate business logic while creating an ASP.NET application? If there is a calendar control to be included in each page of .....

C++ gamedev interview questions

C++ gamedev interview questions This set of questions came from a prominent gaming company. As you can see, the answers are not given (the interviews are typically conducted by senior developers), but there’s a set of notes with common mistakes to avoid. Explain which of the following declarations will compile and .....

Web designer interview questions

Web designer interview questions A reader had to go through the interview for Web Designer / Graphic Designer position and sent in his set of questions. Whats is the difference between cellspacing and cellpadding? If a page has to be loaded over all frames in window, what should be the value .....

VB 6, COM, DCOM, Microsoft platform interview questions

VB 6, COM, DCOM, Microsoft platform interview questions 3 main differences between flexgrid control and dbgrid control ActiveX and Types of ActiveX Components in VB Advantage of ActiveX Dll over ActiveX Exe Advantages of disconnected recordsets Benefit of wrapping database calls into MTS transactions Benefits of using MTS Can database schema .....

SAS interview questions

SAS interview questions What is a universe? Analysis in business objects? Who launches the supervisor product in BO for the first time? How can you check the universe? What are universe parameters? Types of universes in business objects? What is security domain in BO? Where will you find the address of .....

Interview questions for ASP

Interview questions for ASP Used by IBM Consulting Services, according to the site visitor. How many objects are there in ASP? Which DLL file is needed to be registered for ASP? If you want to initialize a global variable for an application, which is the right place to declare .....

Good C++ Interview questions

Good C++ Interview questions TSome good C++ questions to ask a job applicant. How do you decide which integer type to use? What should the 64-bit integer type on new, 64-bit machines be? What’s the best way to declare and define global variables? What does extern mean in a function declaration? What’s the .....

.NET Deployment questions

.NET Deployment questions What do you know about .NET assemblies? Assemblies are the smallest units of versioning and deployment in the .NET application. Assemblies are also the building blocks for programs such as Web services, Windows services, serviced components, and .NET remoting applications. What’s the difference between private and shared assembly? .....

ASP, ADO and IIS interview questions

ASP, ADO and IIS interview questions This came in the mail from the reader who recently went through a job interview process. He didn’t mention the company name. Why do you use Option Explicit? What are the commonly used data types in VBScript? What is a session object? What are the three .....

Load testing SQA interview questions

Load testing SQA interview questions What criteria would you use to select Web transactions for load testing? For what purpose are virtual users created? Why it is recommended to add verification checks to your all your scenarios? In what situation would you want to parameterize a text verification check? Why do .....

Comments »

The URI to TrackBack this entry is: http://career.education4india.com/59/interview-questions-for-c-developers/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed.


verification image, type it in the box


Recently Visited Pages

  • Sethuram Srinivas Charitable Foundation .
    Address The Managing Trustee, Sethuram Srinivas Charitable Foundation , Porur, Chennai,Tamil Nadu. Eligibility a) should have completed 1st year course from Tamilnadu. b) Not less than 75% (.....)
  • Oliver Gatty Studentship
    Address The Registry, University Registry, The Old Eligibility Graduation. Postgraduates are also eligible. Student has to become a member of the Cambridge University, before the (.....)
  • Master's degree in Naval Architecture
    Address Under Secretary National Scholarship Division, Dept. of Education, Govt. of India, NS-5 Section, Room No. 304, 'C' Wing, Shastri Bhavan, New Delhi. Eligibility a) (.....)
  • IAF Education Instructor
    Basic Information regarding Exam Applications are invited from male Indian citizens for selection as an Airman in Education Instructor Trade of the Indian Air (.....)
  • Ontario Institute for Studies in Education (OISE)
    Address The Admission Office of Ontario Institute for Studies in Education (OISE), 252 Bloor Street West, Toronto, Ontario 1V6. Eligibility Candidates of any nationality who (.....)
  • Small Research Studentship
    Address The Tutor for Graduate Students, Sidney Sussex College, Cambridge CB2 3HU, U.K. Eligibility Candidates must have a graduate degree. They must be accepted by (.....)
  • British Telecom Cambridge Scholarships (India)
    Address The Cambridge Common Wealth Trust (TPG ), c/o Nehru Trust for Cambridge University, Teen Murti House, Teen Murti Marg, New Delhi - 110011. Eligibility Candidates (.....)
  • Part-Cost Bursaries
    Address The Cambridge Common Wealth Trust, New Delhi. Selection Scholars & bursars will be selected in June. Other Information Applicants who are not successful in (.....)
  • Scholarship Offer In USSR : Higher Studies In USSR
    Address The Executive Director Indo Soviet Medical Education Care & Research Foundation, 610.Som Dutt Chambers II 9 ,Bhikaji Cama Place, New Delhi. Eligibility For higher (.....)
  • Staines Medical Research Fellowship
    Address The Rector, Exeter College, Oxford OX1 3DP, U.K. Eligibility Candidates with a graduate studentship or postdoctoral position in a Department of the University of (.....)
  • University of Birmingham Neville Camberlain Scholarships
    Address The Academic & Student Division, Office of the Academic Secretary, University of Birmaingham, Birmingham B15 2TT, U.K. Eligibility Candidates must have obtained offer of (.....)
  • NCC Scholarships
    Address Director General, N.C.C. West Block No.4, R.k.puram, Delhi. Eligibility For junior division/wing : 1). Passed in 10th standard with 75% marks 2). N.C.C cadet (.....)
  • Lady Tata Memorial Trust (UK)
    Address Secretary, Scientific Advisory Committee, Lady Tata Memorial Trust, Academic Department of Hematology and Cytogenetics, Royal Marsden Hospital, London, SW3 6JJ, U.K. Eligibility Open to (.....)
  • Coventry University School of Engineering : Overseas Scholarship
    Address Admissions Tutor, School of Engineering, Coventry University, Coventry CV1 5FB, U.K. Eligibility Candidates with all overseas applicants who fulfill the entrance requirements will automatically (.....)
  • Central Industrial Security Force (CISF):Assistant Sub-Inspector(Clerk- Typist) and Sub-Inspector (Steno)
    Basic Information regarding Exam Applications are invited from both male and female Indian citizens for recruitment. to various posts. Details of the two categories (.....)

Latest Education Alerts


All Archive Section : Alerts News 1 2 3 4 CBSE Institutions 1 2 3 4  IGNOU Symbiosis Amity Delhi University Mumbai University Syllabus Scholarship  Bussiness Schools Results Study Abroad Career Forum Archives : 1 2 3 4 Disclaimer   About Us Site Design and SEO by : MAAS InfoMedia
Site best viewed in Opera and Google Chrome browsers with 1024x768 resolution. May not be best viewed in Internet Explorer.