Sunday, May 15, 2005

 

Some DotNet interview questions - 2

I.
Will this code throw an AgrumentNullException? and why?

From http://blogs.msdn.com/brada/archive/2003/04/07/49922.aspx

string firstName = null;
String.Format (“{0}”, firstName);

Here is the for code String.Format , if that helps…

public static String Format(String format, Object arg0) {
return Format(null, format, new Object[] {arg0});
}

public static String Format( IFormatProvider provider, String format, params Object[] args) {
if (format == null || args == null)
throw new ArgumentNullException((format==null)?"format":"args");

StringBuilder sb = new StringBuilder(format.Length + args.Length * 8);
sb.AppendFormat(provider,format,args);
return sb.ToString();
}

Answer: Monday, April 07, 2003 9:03 PM by Brad, Guy of .NET
Whether an exception is thrown or not is irrelevant to the code shown, because none of the code actually tests the arguments for null (only the array of arguments). A peek through StringBuilder.AppendFormat using Anakrino shows this just prior to the append: if (local12 == null) local12 = String.Empty; That's why it doesn't throw. StringBuilder turns null arguments into empty strings.

II.
Will that compile?

From http://blogs.msdn.com/brada/archive/2004/12/21/329270.aspx

A recent internal thread and a little nudge inspired me to offer this little quiz to keep the old grey matter working over the holiday break.

In V2.0, does this code compile? If not why not and how would you fix it?

Obviously the quiz is a little more challenging if you attempt it with out the aid of the compiler…

using System;

using System.Threading;

public class Class1
{
public static void Main () {
new Thread(delegate { Console.WriteLine("On another thread"); }).Start();
}
}

Answer: Tuesday, December 21, 2004 8:54 PM by Judah

new Thread(delegate
{
Console.WriteLine("On another thread");
}).Start();

Would work if 1.1 supported anonymous methods. :-) But in 2.0, Thread.Start has overloads allowing a parameterized thread start, which means the compiler can't figure out which one to use, ThreadStart or ParameterizedThreadStart. So no, it won't compile.

This should compile:

// tell the compiler it should be a ThreadStart
new Thread((ThreadStart)delegate
{
Console.WriteLine("On another thread");
});

III.
const vs. readonly

From http://blog.joycode.com/jgtm2000/archive/2003/12/02/8240.aspx

关于C#中的const和readonly想必使用C# .NET开发的朋友都很了解吧?总结一下const和readonly也就这么几条吧:

const和readonly的值一旦初始化则都不再可以改写;
const只能在声明时初始化;readonly既可以在声明时初始化也可以在构造器中初始化;
const隐含static,不可以再写static const;readonly则不默认static,如需要可以写static readonly;
const是编译期静态解析的常量(因此其表达式必须在编译时就可以求值);readonly则是运行期动态解析的常量;
const既可用来修饰类中的成员,也可修饰函数体内的局部变量;readonly只可以用于修饰类中的成员(UPDATED:谢谢MicroHelper的提醒!)。

IV.
From http://www.code101.com/Code101/Quiz/Quiz.aspx?qid=3

1. When will the garbage collector run?

Every 15 minutes
Once every day at 1:00 am
When the application is low on memory (X)
Randomly based on the resource load on the system

2. Which of the following accurately describes a strong named assembly?

A private assembly with a unique name within an application domain
A private assembly with a unique name within a global domain (X)
A shared assembly with a unique name within an application domain
A shared assembly with a unique name within a global domain

3. The statement that is used to replace multiple if statements is called

The case statement (X)
The switch statement
The nestedif statement
The #endif statement

4. You have been asked to debug a Web-based ASP.NET application. For some reason, the debugging information is not presented. What could be missing?

<%@ Page Debug="true" %> (X)
<%@ Application Debug="true" %>
<%@ Page Trace="true" %>
<%@ Application Trace="true" %>

5. Which of the following is not a C# keyword?

if
delegate
private
implements (X)
Please choose an answer.

6. Which tool would you use? if you want to see all the methods of a particular class in your application

Class Viewer
Object Browser (X)
Class Explorer
Object Explorer

7. Trace switches can be set using which class?

System.Diagnostics.Trace
System.Diagnostics.DefaultTraceListener
System.Diagnostics.TraceSwitches
System.Diagnostics.TraceSwitch (X, the original answer on that web is wrong, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebTraceContextClassTopic.asp)

8. What is the name given to the type of assembly that contains localized resources?

Spoke
Hub
Sputnik
Satellite (X)

9. What is the correct name for a resource file with images for the English culture,in the United States subculture?

images.US-en.resources
images.en-US.resources (X)
resources.images.en-US
images.en-US.dll

10. What is the minimum number of assemblies a .NET application can have?

0
1 (X)
2
3

11. Which tool allows you to install an assembly into the GAC?

Ngen.exe (X)
Mscorcfg.msc
Setup.exe
sn.exe

12. How is the metadata for an assembly stored?

In the Registry
In .ini files
As XML in the manifest (X)
As a Type Library (.tlb) file

13. What tool is used to manage the assemblies in the Global Assembly Cache?

gacmgr.exe
gacutil.exe (X)
gassy.exe
al.exe

14. Your application is called AccountingOne.exe. What must the name of the satellite assemblies be?

Accountingone.resources.dll
Accounting.Resources.dll
AccountingOne.resources.dll (X)
Accounting.resources.dll

15. Your application is called AccountingOne.exe. What must the name of the French string resource be?

AccountingOne.resources.dll
strings.resources
strings.fr.resources.dll
strings.fr.resources (X)

16. Which command will cause an XML file to be generated from documentation comments?

csc MyClass.cs /doc:MyClass.cs
cscd MyClass.cs /doc:MyClass.xml
cscd MyClass.cs /doc:MyClass.cs
csc MyClass.cs /doc:MyClass.xml (X)

17. If you want to ask the user to select between two or more mutually exclusive options, you would employ which of the following controls?

TabControl
Button
RadioButton (X)
CheckBox

18. Which of the following command-line entries would allow you to install an assembly into the GAC?

gacutil /l myAssembly.exe
gacutil /i myAssembly.exe (X)
gacutil /s myAssembly.exe
gacutil /h myAssembly.exe

19. Which command would you use to list the existing files in the native image cache?

Ngen.exe /list
Ngen.exe /cache
Ngen.exe /debug
Ngen.exe /show (X)

20. Which of the following represents a union of permissions?

A collection of code groups (X)
A collection of permissions
A collection of intersections
A collection of evidence

V.
From http://www.dotnetcoders.com/web/Apps/Quiz/default.aspx

1 . What is the full version number of .NET RTM?
1.0.3700
1.0.3705
1.0.3715
1.0.3716


2 . Shared assemblies are installed where?
System Assembly Cache
Global Assembly Cache
Machine Assembly Cache
Windows Assembly Cache


3 . What is the default value for the Char type?
'0'
''
'\0'
null


4 . Which type of class can you develop to alter SOAP messages sent to and from an XML Web service and client?
SOAP Messages
SOAP Alterations
SOAP Configurations
SOAP Extensions


5 . Which of the following is a value type, and not a reference type?
array
delegate
enum
class


6 . What two methods for initializing data are used in SOAP extensions?
OnInitialize and Initialize
GetInitializer and Initialize
InitializeService and InitializeMethod
InitializeService and Initializer


7 . Which of the following operators has the highest precedence?
Pre Increment (++x)
Shift bits left: <<
Bitwise Or: |
Post Increment (x++)


8 . C# was developed by a small team led by which two Microsoft distinguished engineers?
Anders Hejlsberg and Scott Wiltamuth
Doug Seven and Donny Mack
Scott Guthrie and Mark Anders
Mark Lucovksy and Peter Spiro


9 . What is the term used to describe the process the Runtime uses to find an assembly?
Locating
Probing
Searching
Resolving


10 . When creating a C# Class Library project, what is the name of the supplementary file that Visual Studio.NET creates that contains General Information about the assembly?
AssemblyInfo.xml
AssemblyInfo.cs
AssemblyInformation.cs
AssemblyAttributes.cs


11 . C# types are defined in ____________, organized by ____________, compiled into __________, and then grouped into ____________.
files, modules, namespaces, assemblies
files, namespaces, assemblies, modules
files, assemblies, namespaces, modules
files, namespaces, modules, assemblies


12 . Which of the following is not a valid value in the SoapMessageStage enumeration?
BeforeSerialize
AfterSerialize
BeforeDeserialize
EndSerialize


13 . All types derive from a single base type called:
System.Base
System.Object
System.Root
System.Type


14 . A refernce to a reference-type instance requires how many bytes?
2 bytes
4 bytes
8 bytes
16 bytes


15 . Which interface allows a collection to be navigated using the foreach statement?
INavigator
ICollection
IEnumerator
IEnumerable


16 . In C#, which of the following is not a valid C# jump statement?
jump
goto
return
throw


17 . When an integral literal is valid for several possible integral types, the default type chosen goes in which order?
uint, int, ulong, long
long, ulong, int, uint
ulong, long, uint, int
int, uint, long, ulong


18 . The CLR uses which format for assembly version numbers?
Major:Minor:Revision:Build
Major:Build:Minor:Revision
Major:Revision:Minor:Build
Major:Minor:Build:Revision


19 . Which of the following is the C# escape character for Null?
\n
\0
\f
\v


20 . What is the exception that is thrown when there is an attempt to dynamically access a method that does not exist?
MissingMethodException
TypeLoadException
MethodLoadException
MethodAccessException

1. What is the full version number of .NET RTM?
Correct answer: B. 1.0.3705

2. Shared assemblies are installed where?
Correct answer: B. Global Assembly Cache

3. What is the default value for the Char type?
Correct answer: C. '\0'

4. Which type of class can you develop to alter SOAP messages sent to and from an XML Web service and client?
Correct answer: D. SOAP Extensions

5. Which of the following is a value type, and not a reference type?
Correct answer: C. enum

6. What two methods for initializing data are used in SOAP extensions?
Correct answer: B. GetInitializer and Initialize

7. Which of the following operators has the highest precedence?
Correct answer: D. Post Increment (x++)

8. C# was developed by a small team led by which two Microsoft distinguished engineers?
Correct answer: A. Anders Hejlsberg and Scott Wiltamuth

9. What is the term used to describe the process the Runtime uses to find an assembly?
Correct answer: B. Probing

10. When creating a C# Class Library project, what is the name of the supplementary file that Visual Studio.NET creates that contains General Information about the assembly?
Correct answer: B. AssemblyInfo.cs

11. C# types are defined in ____________, organized by ____________, compiled into __________, and then grouped into ____________.
Correct answer: D. files, namespaces, modules, assemblies

12. Which of the following is not a valid value in the SoapMessageStage enumeration?
Correct answer: D. EndSerialize

13. All types derive from a single base type called:
Correct answer: B. System.Object

14. A refernce to a reference-type instance requires how many bytes?
Correct answer: B. 4 bytes

15. Which interface allows a collection to be navigated using the foreach statement?
Correct answer: D. IEnumerable

16. In C#, which of the following is not a valid C# jump statement?
Correct answer: A. jump

17. When an integral literal is valid for several possible integral types, the default type chosen goes in which order?
Correct answer: D. int, uint, long, ulong

18. The CLR uses which format for assembly version numbers?
Correct answer: D. Major:Minor:Build:Revision

19. Which of the following is the C# escape character for Null?
Correct answer: B. \0

20. What is the exception that is thrown when there is an attempt to dynamically access a method that does not exist?
Correct answer: A. MissingMethodException

VI.
http://blog.joycode.com/zhanbos/category/778.aspx?Show=All



<< Home

This page is powered by Blogger. Isn't yours?