C# Question Bank and More
C# Question Bank and More
Select Answer :
Answer : 4
Select Answer :
1. Private by default
2. Public by default
3. protected
4. Friend
Answer: 2
Select Answer:
1. System.Net.All
2. System.IO
3. System.Collections
4. System.Object
Answer: 4
Select Answer :
1. Overload
2. Virtual
3. Imaginary
4. Overridden
Answer: 4
5. C# provides a default constructor for me. I write a constructor that takes a string as a
parameter, but want to keep the no parameter one . How many constructors should I write?
Select Answer :
1. One
2. Two
3. Three
4. None of the above
Answer: 2
Select Answer :
1. Yes
2. Partially
3. No
4. None of the above
Answer: 3
Select Answer:
Answer: 4
8. What’s the implicit name of the parameter that gets passed in to the class’ set method?
Select Answer :
1. value
2. Datatype
3. value and its datatype
4. none of the above
Answer: 3
9. How can you sort the elements of the array in descending order?
Select Answer :
1. Desc()
2. ASCReverse()
3. By calling Sort() and then Reverse() methods
4. By calling ascen() and then Reverse() methods
Answer: 3
Select Answer:
1. Yes
2. No
3. Either 1 or 2
4. None
Answer : 2
Select Answer :
Answer: 1
Answer: 4
13. Which of these string definitions will prevent escaping on backslashes in C#?
Select Answer :
Answer: 3
Select Answer :
1. System.Int16
2. System.Int32
3. System.Int64
4. System.Int128
Answer: 2
15. Loading of .Net Assembly in Windows 98/ME is different than execution in Windows XP.
Select Answer :
1. Yes
2. No
3. Cant say
Answer: 1
16. Which program control statements aways executes the internal statements at least once?
Select Answer :
1. do{Statements}j=j+1;
2. if(j!=1){Statements} j = j+1;
3. while(j!=1){Statements} j=j+1;
Answer: 1
Select Answer :
1. Iunknown
2. IEnumerable
3. Enumerator
4. Idisposable
Answer: 1
18. Which interface allows a collection to be navigated using the foreach statement?
Select Answer :
1. IEnumerable
2. IUnknown
3. IEnumerator
4. Idisposable
Answer: 1
19. Term for the process by which the Runtime uses to find an assembly?
Select Answer :
1. Searching
2. Probing
3. Sorting
4. Caching
5. Bubbling
Answer: 2
1. A try statement can only have one catch{} statement(general catch clause)
2. general clause; if one is present it must be the last catch clause
3. general clause ; may also catch exceptions from other languages
4. “catch(Exception ex),-” is more powerful
5. 1,2&3
Answer: 5
Select answer :
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
Answer: 4
Select Answer :
1. int[,] myArray;
2. int[][] myArray;
3. int[2] myArray;
4. System.Array[2] myArray;
Answer: 1
23. Is it possible to restrict the scope of a field/method of a class to the classes in the same
namespace?
Select Answer :
1. There is no way to
2. restrict to a namespace. Namespaces are never units of protection
3. But if you’re using assemblies, you can use the ‘internal’
4. access modifier to restrict access to only within the assembly
Answer: 1
24. Is it possible to have different access modifiers on the get/set methods of a property?
Select Answer :
1. No. The access modifier on a property applies to both its get and set accessors
2. 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
Answer: 1
Select Answer :
Answer: 1
26. For which of the following protocols is The Internet Transfer control used ?
Select Answer :
1. TCP only
2. FTP and TCP
3. FTP and IPX
4. HTTP and TCP
5. FTP and HTTP
Answer: 1
Scenario : A public string property called Name has been added to class called Employee
Select Answer :
1. Person.Name
2. Employee!Person.Name
3. Person ->Name
4. Person(“Name”)
5. Employee.Name
Answer: 1
1. Reflection
2. Remoting
3. Delegates
4. web service
Answer: 3
Int i=0;
While(i++<10)
Console.WriteLine(“i=”+i);
Select Answer :
1. Compile Error
2. Runtime Error
3. 10
4. 11
5. None of the above
Answer: 4
30. What is the term for assemblies that are marked for aspecific culture via their
AssemblyCultureAttribute?
1. Global assemblies
2. Satellite assemblies
3. Universal assemblies
4. Dynamic assemblies
Answer: 1
31. Which one of the following is the term used to describe the basic unit of deployment and
versioning in the .NET Framework?
Select Answer :
1. Library
2. Managed Module
3. .NET Portable Executable (PE) file
4. Assembly
Answer: 4
32. Which one of the following statements is true about events and delegates ?
Select Answer :
Answer: 4
Select Answer :
1. Major.Minor.Build.Revision
2. Revision.Major.Minor.Build
3. Major.Minor.Revision.Build
4. Build.Major.Minor.Revision
5. Minor.Build.Major.Revision
Answer: 3
Select Answer :
1. Yes
2. No
3. Some Time
4. Don’t know
Answer: 1
example:
interface ISample
{
int sample ;
void DisplaySample();
Select Answer :
Answer: 1
Select Answer :
1. only one
2. two
3. ten
4. any number
Answer: 4
Select Answer :
Answer: 2
int GetSalary();
this.salary = salary;
return salary;
salary+= amount;
class Test
System.Console.WriteLine(c.GetSalary());
Select Answer :
Answer: 4
39. What output would you expect from the following code ?
Using System;
Class A
Console.Write(“A”);-
class B : A
,Console.Write(“B”);-
class C : B
class D:C
,Console.Write(“D”);-
class Test
D d =new D();
A a = d;
B b =d ;
C c =d;
a.F();
b.F();
c.F();
d.F();
Select Answer :
1. BBDD
2. BBCD
3. ABCD
4. ABBC
Answer: 1
Select Answer :
1. static methods
2. objects
3. instance methods
4. events
Answer: 2
byte b1 =1;
byte b2 = 255;
Console.WriteLine(total);
Select Answer :
Answer: 2
Select Answer :
Answer: 3
Select Answer :
1. Yes
2. No
3. I don’t know
4. All the above
Answer: 2
44. What are interface class?
Select Answer :
Answer: 3
45. Will finally block get executed if the exception had not occurred ?
Select Answer :
1. No
2. Yes
3. Both
4. I don’t know
Answer: 2
46. Which is the main CLR System assembly which contains the classes for built – in CLR types?
Select Answer :
1. base
2. mscorlib
3. 1&2
4. none
Answer: 2
47. What is the output of following c# code ?
Using System;
Class MainClass
{
Console.WriteLine(new Pointer()argPointer)(aNumber) -1);
Console.Write(aNumber);
Return aNumber+1;
Select Answer :
1. 363536
2. 353637
3. 353536
4. 373635
5. 353636
Answer: 5
Select answer :
1. vb.net
2. c#
3. JScript.net
4. j#.net
Answer: 2
49. In C# properties and methods are non – virtual by default, which means they can’t be
overridden in a derived class
Select Answer :
1. true
2. false
Answer: 1
50. What is the default initial capacity of a hashtable?
Select answer :
1. 16
2. 0
3. 24
4. -1
Answer: 2
51. What would be the output of the following program?
myArrayList.TrimToSize();
Console.WriteLine(myArrayList.Capacity.ToString());
Select Answer :
1. 16 (*)
2. 0
3. ArgumentNullException, since the ArrayList contains no values
Answer: 1
myArrayList.Add(“Thank you”);
myArrayList.Add(“For”);
myArrayList.Add(“Visiting”);
Console.WriteLine(myArrayList.LastIndexOf(myString).ToString());
Select Answer :
1. 0
2. 1
3. -1
4. ArgumentNullException
Answer: 3
53. If my ArrayList is an ArrayList with the element “1” and myQueue is a Queue with the
element “A”, what would be the output of the following program?
myArrayList.AddRange(myQueue);
foreach(string s in myArrayList)
Console.Write(s+”,”);
Select Answer :
1. 1, A
2. A,1
3. A
4. 1
Answer: 1
Select answer :
Answer: 2
Console.WriteLine(myArrayList.Capacity.ToString());
Select answer :
1. Ten
2. Twelve
3. Fourteen
4. Sixteen
Answer: 4
Select answer :
1. 1
2. many
3. 4
4. 5
Answer: 2
Select Answer :
Answer: 2
Select answer :
1. By Incapsulation
2. By Main function
3. By using Abstract classes/functions
4. By Using Implementation
Answer: 3
Select answer :
Answer: 3
Answer: 3
string str;
i =2005;
str = str+i;
Console.WriteLine(str);
Select answer :
Answer: 4
Byte a = 5 ;
Byte b = 255;
Console.WriteLine(total);
Select answer :
1. 260
2. 1
3. Run –time error
4. Compilation Error
Answer: 4
Select answer :
1. COM + component
2. A .Net DLL
3. .Net executable file contains user interface text information
Answer: 3
Ex :
if NULL = NULL
[True Part]
Else
[False Part]
Select answer :
1. True
2. False
3. Fatal Error
Answer: 1
Using System :
Class main
static main()
{
Console.WriteLine(afield);
main()
afield = 1000;
Console.WriteLine(afield);
Select answer :
1. 1000 123
2. 123
3. no output
4. 123 1000
Answer: 4
66. Which is the correct statement in the following to set the alias name for namespace in C#?
Select Answer :
Answer: 2
Select answer :
1. Virtual Class
2. Sealed Class
3. Abstract Class
4. Final Class
Answer: 2
Using System ;
Class AClass
ushort aField;
Class MainClass
Select Answer :
1. 33
2. Syntax Error *Cannot access ‘AnObj’ in ‘static void Main()’+
3. 44
4. 3344
5. 4433
Answer: 2
Class AClass
sbyte aField ;
this.aField = aField;
System.Console.Write(aField);
class MainClass
select answer :
1. 7
2. 8
3. 78
4. 87
5. No output
Answer: 1
70. Which of the following are/is value type datatypes of C#?
Select answer :
1. String
2. Object
3. Struct
4. 1&2
5. All
Answer: 3
Class AClass
sbyte aField ;
this.aField = aField;
System.Console.Write(aField);
class MainClass
static MainClass()
Select answer :
1. 5-2
2. 5-29
3. -25 (*)
4. -259
5. -295
Answer: 3
72. Which operating system has the .NET Framework and Common Language Runtime(CLR)
natively installed?
Select answer :
Answer: 2
73. From which one of the following locations does the garbage collector remove objects?
Select answer :
Answer: 4
int i = 10 ;
try
Console.Write(“I= ”+ i);
catch(Exception ex)
Console.WriteLine(ex.Message);
finally
return;
Select answer :
1. yes
2. No
Answer: 1
75. Choose the correct differentces between a class and a structure from the following
Select answer :
Answer: 4
Select answer :
1. I = Integer.Parse(S)’Where I is an integer and S is a string
2. I = Parse(S)’Where I is an integer and S is a string
3. S = Parse(I)’Where I is an integer and S is a string
4. None
Answer: 1
Select Answer :
1. Parsing
2. Boxing
3. Buffering
4. None
Answer: 2
Select Answer :
1. System.file
2. System.FileIO
3. System.IO
4. System.Access
Answer: 3
79. When creating an array of reference types , declaring and initializing an array implies
Select answer :
Answer: 2
class MainClass
{ System.Console.Write(aField);
MainClass()
aField = 1000;
System.Console.Write(aField);
Select answer :
1. 1212
2. 1000
3. No output
4. Syntax Error*Class MainClass already defines a member ‘MainClass()’+
5. Syntax Error *No executable statements in entry point ‘Main()’+
Answer: 1
Class MainClass
static MainClass()
System.Console.Write(“Static ”);
public MainClass()
{
System.Console.Write(“Instance”);
class AClass
new MainClass();
Select answer :
Answer: 5
class MainClass
int i = 10 ;
uint j =2 ;
i = i + j;
System.Console.Write(i);
}
}
Select Answer :
1. Throws ‘InvalidCastException’
2. 12
3. Syntax Error*Cannot implicitly convert type ‘long’ to ‘int’+
4. Syntax Error *Cannot implicitly convert type ‘int’ to ‘uint’+
5. Syntax Error *Cannot implicitly convert type ‘uint’ to ‘int’+
Answer: 3
Class MainClass
int I = 10;
uint j =2;
i+ = j;
System.Console.Write(i);
Select Answer :
1. Throws ‘InvalidCastException’
2. 12
3. Compiler Warning [Cannot implicitly convert type ‘int ’ to ‘uint’+
4. Syntax Error *Cannot implicitly convert type ‘int’ to ‘uint’+
5. Syntax Error *cannot implicitly convert type ‘uint’ to ‘int’+
Answer: 5
Select answer :
1. float(16 -bit)
2. float(32 -bit)
3. float(64 - bit)
4. float(128 -bit)
5. decimal(128 - bit)
Answer: 2
Select answer :
1. System.Float
2. System.Single
3. System.Decimal (*)
4. System.Double
5. System.Real
Answer: 3
Select answer :
Answer: 1
Select Answer :
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
Answer: 4
using System;
class MainClass
{
Console.Write(“,0-,1-,2-,3-”,true^true,true^false, false^true,false^false);
Select answer:
Answer: 5
Select Answer :
1. System.Byte
2. System.Int 16
3. System.Int 32
4. System.Int 64
5. System.Int 128
Answer: 3
F static modifier can be used with local variables declared within a method
Select answer :
Answer: 1
class MainClass
class InnerClass
Select answer :
Answer: 1
}
}
Select answer :
1. private
2. public
3. protected
4. internal
5. protected internal
Answer: 4
Class MainClass
{ System.Console.Write((int)(Vibgyor.Red));
Red,
Violet,
Indigo,
Blue,
Green,
Yellow,
Orange = 255,
Select answer :
1. 0
2. 256
3. Syntax Error *enumerator value ‘Vibgyor.Red’ is too large to fit in its type+
4. Syntax Error *cannot cast ‘vibgyor.Red’ to ‘int’+
5. 1
Answer: 1
A.
//block of statements
return (0);
B.
//block of statements
return ;
C.
//block of statements
return 1;
D.
//block of statements
return 0;
E.
//block of statements
Select answer :
1. D& E
2. D
3. A& C
4. B
5. A&D
Answer: 2
Select answer :
Answer: 4
Select answer :
1. Value type
2. Reference type
Answer: 2
Select answer :
Answer: 2
Select answer :
Answer: 1
99. Advantages of writing a managed code application instead of unmanaged code application
Select answer :
Answer: 5
Select answer :
1. Private Assembly
2. Shared Assembly
3. Can be used in both Private and Shared Assembly
4. In Private assembly but with certain conditions
5. In Shared assembly but with certain conditions
Answer: 2
1. !—Data
2. //Data
3. /*Data
4. –Data
Answer: 2
Select answer :
1.
2. //Data//
3. /*Date*/
4. Data-->
Answer: 3
Select answer:
1. True
2. fasle
3. Not a relevant comparison
Answer: 2
Select answer:
1. True
2. False
3. Not a relevant comparison
Answer:
Select Answer :
Select answer :
1. True
2. False
3. I don’t know
Answer: 2
107. Which tool use to register a shared assembly to global assemblies cache?
Select answer :
Answer: 3
Select answer :
1. MyArray.Add(new value)
2. MyArray[MyArray.Length] = new value
3. Cannot do that
4. MyArray[MyArray.Length -1] = new value
Answer: 3
class ClassA
/*Do something*/
}
interface interfaceB : ClassA
/*Do something*/
class MainClass
//block of statements
Select answer :
1. Nothing wrong
2. Compiler error
3. Runtime error
4. Whatever
Answer: 2
110. What’s the .NET datatype that allows the retrieval of data by a unique key?
Select answer :
1. Primary
2. Integer
3. Unique Identifier
4. HashTable
Answer: 4
Select answer :
1. public
2. private
3. internal
4. protected
Answer: 2
112. A character in C# is an
Select Answer :
Answer: 2
113. If there are two interfaces having a same function which have same signature and
we are implementing both the interfaces in C# class then how will we define the methods in
our C# class?
Select answer :
Answer: 3
114. What is the difference between a virtual function and a abstract function ?
Select answer :
1. No difference
2. A virtual function can be overridden but an abstract cannot be overridden
3. A abstract function can be overridden but an virtual function cannot be overridden
Answer: 3
int i =12 ;
object obj = i;
i = 34;
Console.WriteLine(obj);
1. 12
2. 34
3. Compile error
4. Runtime it caught Exception
Answer: 1
Select answer :=
Answer: 3
117. In C#, the members inherited from the base class may not include which of the
following ?
Select answer :
1. constants
2. fields
3. methods
4. properties
5. None of the above choices
Answer: 5
118. The following code is meant to handle exceptions. Explain why this code is not
correct
1. try
2. {
3. …
4. }
5. catch(Exception),…-
6. catch(IOException),…-
Select answer :
1. We can’t use the type of IOException class as catch parameter here as such class doesn’t
exist
2. The code generates a compile time error because the most general exception is caught first
3. The type of class Exception can’t be used as catch parameter
4. This code is absolutely correct
Answer: 2
119. To convert a private assembly to a shared assembly which of the following should
you perform ?
Select answer :
Answer: 4
120. It is possible for a derived class to define a member that has the same name as the
member in its base class. Which of the following keywords would you use If your intent is to
hide the base class member?
Select answer:
1. virtual
2. sealed
3. ref
4. new
Answer: 4
Select answer :
1. False
2. True, you do this by prefixing the identifier with an @ symbol
3. True, you do this by suffixing the identifier with an @ symbol
4. True, you do this by suffixing the identifier with an & symbol
Answer: 2
C# 2.0 QUESTIONS
122. Which of the following are value types? (Choose all that apply.)
A. Decimal
B. String
C. System.Drawing.Point
D. Integer
Answers: A, C, and D
Answer: B
A.
Nullable(int) i = null;
B.
Nullable<int> i = null;
C.
int i = null;
D.
int<Nullable> i = null;
Answer: B
125. You need to create a simple class or structure that contains only value
types. You must create the class or structure so that it runs as efficiently as
possible. You must be able to pass the class or structure to a procedure without
concern that the procedure will modify it. Which of the following should you
create?
A. A reference class
B. A reference structure
C. A value class
D. A value structure
Answer: D
126. Which of the following are reference types? (Choose all that apply.)
Answers: B and C
127. What is the correct order for Catch clauses when handling different
exception types?
Answer: C
128. When should you use the StringBuilder class instead of the String class?
Answer: A
129. Why should you close and dispose of resources in a Finally block instead
of a Catch block?
Answer: B
130. Which of the following statements are true? (Choose all that apply.)
Answers: B and C
131. Which of the following are examples of built-in generic types? (Choose all
that apply.)
A. Nullable
B. Boolean
C. EventHandler
D. System.Drawing.Point
Answers: A and C
132. You are creating a generic class, and you need to dispose of the generic
objects.
How can you do this?
Answer: D
133. You’ve implemented an event delegate from a class, but when you try to
attach
an event procedure you get a compiler error that there is no overload that
matches the delegate. What happened?
A. The signature of the event procedure doesn’t match that defined by the
delegate.
B. The event procedure is declared Shared/static, but it should be an instance
member instead.
C. You mistyped the event procedure name when attaching it to the delegate.
D. The class was created in a different language.
Answer: A
A. It adds overhead.
B. Users must have administrative privileges to run the application.
C. It makes code less readable.
Answer: A
A. To avoid boxing.
B. To return something other than the type name.
C. The compiler requires structures to override the ToString method.
D. To avoid run-time errors caused by invalid string conversions.
Answers: A and B
136. If there is no valid conversion between two types, what should you do
when
implementing the IConvertible interface?
Answer: B
137. With strict conversions enabled, which of the following would allow an
implicit
conversion? (Choose all that apply.)
A. Int16 to Int32
B. Int32 to Int16
C. Int16 to Double
D. Double to Int16
Answers: A and C
138. Which are acceptable ways to open a file for writing? (Choose all that
apply.)
A.
File.Open("somefile.txt", FileMode.Create);
B.
File.Open("somefile.txt", FileMode.Create, FileAccess.Write);
C.
File.Open("somefile.txt", FileMode.Create, FileAccess.Read);
D.
FileInfo file = new FileInfo("somefile.txt");
file.Open(FileMode.Create);
Answers: A, B, and D
139. Which of the following are types of changes that can be detected by the
FileSystemWatcher? (Choose all that apply.)
A. New files
B. New directories
C. Changed files
D. Renamed files
E. None
Answers: A, B, C, and D
140. The following code changes the extension of a file. (True or False)
string ourPath = @"c:\boot.ini";
Path.ChangeExtension(ourPath, "bak");
A. True
B. False
Answer: B
141. Which methods of the FileStream class affect the Position property?
(Choose all that apply.)
A. Read
B. Lock
C. Write
D. Seek
Answers: A, C, and D
Answers: A, B, and C
143. Which of the following create a FileStream for writing when you want to
open an existing file or create a new one if it doesn’t exist? (Choose all that
apply.)
A. Create a new instance of the FileStream class, with the FileMode option of
OpenOrCreate.
B. Call File.Create to create the FileStream.
C. Call File.Open with the FileMode option of OpenOrCreate.
D. Call File.Open with the FileMode option of Open.
Answers: A and C
144. When compressing data with the DeflateStream class, how do you specify
a stream into which to write compressed data?
A. Set the BaseStream property with the destination stream, and set the
CompressionMode
property to Compression.
B. Specify the stream to write into when the DeflateStream object is created
(for example, in the constructor).
C. Use the Write method of the DeflateStream class.
D. Register for the BaseStream event of the DeflateStream class.
Answer: B
145. What types of data can a GZipStream compress? (Choose all that apply.)
A. Any file
B. Any data
C. Any data less than 4 GB in size
D. Any file no larger than 4 GB in size
Answers: C and D
A. IsolatedStorageFile.GetStore
B. IsolatedStorageFile.GetMachineStoreForAssembly
C. IsolatedStorageFile.GetUserStoreForAssembly
D. IsolatedStorageFile constructor
Answers: A, B, and C
A. True
B. False
Answer: A
148. You are writing an application to update absolute hyperlinks in HTML files.
You have loaded the HTML file into a String named s. Which of the following code
samples best replaces “http://” with “https://”?
A.
s = Regex.Replace(s, "http://", "https://");
B.
s = Regex.Replace(s, "https://", "http://");
C.
s = Regex.Replace(s, "http://", "https://", RegexOptions.IgnoreCase);
D.
s = Regex.Replace(s, "https://", "http://", RegexOptions.IgnoreCase);
Correct Answer: C
149. You are writing an application to process data contained in a text form.
Each file contains information about a single customer. The following is a sample
form:
First Name: Tom
Last Name: Perham
A.
string p = @"First Name: (?<firstName>.*$)\n" +
@"Last Name: (?<lastName>.*$)\n" +
@"Address: (?<address>.*$)\n" +
@"City: (?<city>.*$)\n" +
@"State: (?<state>.*$)\n" +
@"Zip: (?<zip>.*$)";
Match m = Regex.Match(s, p, RegexOptions.Multiline);
string fullName = m.Groups["firstName"] + " " + m.Groups["lastName"];
string address = m.Groups["address"].ToString();
string city = m.Groups["city"].ToString();
string state = m.Groups["state"].ToString();
string zip = m.Groups["zip"].ToString();
B.
string p = @"First Name: (?<firstName>.*$)\n" +
@"Last Name: (?<lastName>.*$)\n" +
@"Address: (?<address>.*$)\n" +
@"City: (?<city>.*$)\n" +
@"State: (?<state>.*$)\n" +
@"Zip: (?<zip>.*$)";
Match m = Regex.Match(s, p);
string fullName = m.Groups["firstName"] + " " + m.Groups["lastName"];
string address = m.Groups["address"].ToString();
string city = m.Groups["city"].ToString();
string state = m.Groups["state"].ToString();
string zip = m.Groups["zip"].ToString();
C.
string p = @"First Name: (?<firstName>.*$)\n" +
@"Last Name: (?<lastName>.*$)\n" +
@"Address: (?<address>.*$)\n" +
@"City: (?<city>.*$)\n" +
@"State: (?<state>.*$)\n" +
@"Zip: (?<zip>.*$)";
Match m = Regex.Match(s, p, RegexOptions.Multiline);
string fullName = m.Groups["<firstName>"] + " " + m.Groups["<lastName>"];
string address = m.Groups["<address>"].ToString();
string city = m.Groups["<city>"].ToString();
string state = m.Groups["<state>"].ToString();
string zip = m.Groups["<zip>"].ToString();
D.
string p = @"First Name: (?<firstName>.*$)\n" +
@"Last Name: (?<lastName>.*$)\n" +
@"Address: (?<address>.*$)\n" +
@"City: (?<city>.*$)\n" +
@"State: (?<state>.*$)\n" +
@"Zip: (?<zip>.*$)";
Match m = Regex.Match(s, p);
string fullName = m.Groups["<firstName>"] + " " + m.Groups["<lastName>"];
string address = m.Groups["<address>"].ToString();
string city = m.Groups["<city>"].ToString();
string state = m.Groups["<state>"].ToString();
string zip = m.Groups["<zip>"].ToString();
Correct Answer: A
150. Which of the following regular expressions matches the strings “zoot” and
“zot”?
A. z(oo)+t
B. zo*t$
C. $zo*t
D. ^(zo)+t
Correct Answer: B
152. Which of the following encoding types would yield the largest file size?
A. UTF-32
B. UTF-16
C. UTF-8
D. ASCII
Correct Answer: A
153. Which of the following encoding types support Chinese? (Choose all that
apply.)
A. UTF-32
B. UTF-16
C. UTF-8
D. ASCII
154. You need to decode a file encoded in ASCII. Which of the following
decoding types would yield correct results? (Choose all that apply.)
A. Encoding.UTF32
B. Encoding.UTF16
C. Encoding.UTF8
D. Encoding.UTF7
155. You are writing an application that generates summary reports nightly.
These reports will be viewed by executives in your Korea office and must contain
Korean characters. Which of the following encoding types should you use?
A. iso-2022-kr
B. x-EBCDIC-KoreanExtended
C. x-mac-korean
D. UTF-16.
Correct Answer: D
A. Remove
B. Contains
C. IndexOf
D. Count
157. What is the Comparer class used for? (Choose all that apply.)
158. What does the Dequeue method of the Queue class do? (Choose all that
apply.)
159. In what order does a Stack retrieve items as you use its Pop method?
A. Random order
B. First-in, first-out
C. Last-in, first-out
D. Last-in, last-out
Correct Answer: C
160. When adding a key to a Hashtable, what methods can be called on the key
to
determine whether the key is unique? (Choose all that apply.)
A. GetType
B. GetHashCode
C. ToString
D. Equals
Correct Answer: A
162. What types of collections can be made from the CollectionsUtil class?
(Choose all that apply.)
A. Case-insensitive StringDictionary
B. Culture-invariant Hashtable
C. Case-insensitive Hashtable
D. Case-insensitive SortedList
A. Strings
B. Objects
C. Arrays of strings
D. Any .NET Types
Correct Answer: A
164. What kind of object does the generic Dictionary enumerator return?
A. Object
B. Generic KeyValuePair objects
C. Key
D. Value
Correct Answer: B
165. Where can you add items to a LinkedList? (Choose all that apply.)
166. Which of the following are required to serialize an object? (Choose all that
apply.)
A. An instance of BinaryFormatter
B. File permissions to create temporary files
C. Internet Information Services
D. A stream object
Answers: A and D
167. Which of the following attributes should you add to a class to enable it to
be serialized?
A. ISerializable
B. Serializable
C. SoapInclude
D. OnDeserialization
Answer: B
168. Which of the following attributes should you add to a member to prevent it
from being serialized by BinaryFormatter?
A. NonSerialized
B. Serializable
C. SerializationException
D. SoapIgnore
Answer: A
169. Which of the following interfaces should you implement to enable you to
run a method after an instance of your class is serialized?
A. IFormatter
B. ISerializable
C. IDeserializationCallback
D. IobjectReference
Answer: C
170. Which of the following are requirements for a class to be serialized with
XML serialization? (Choose all that apply.)
A. The class must be public.
B. The class must be private.
C. The class must have a parameterless constructor.
D. The class must have a constructor that accepts a SerializationInfo parameter.
Answers: A and C
171. Which of the following attributes would you use to cause a member to be
serialized as an attribute, rather than an element?
A. XmlAnyAttribute
B. XMLType
C. XMLElement
D. XMLAttribute
Answer: D
172. Which tool would you use to help you create a class that, when serialized,
would produce an XML document that conformed to an XML schema?
A. Xsd.exe
B. Xdcmake.exe
C. XPadsi90.exe
D. Xcacls.exe
Answer: A
173. Which of the following attributes should you add to a member to prevent it
from being serialized by XML serialization?
A. XMLType
B. XMLIgnore
C. XMLElement
D. XMLAttribute
Answer: B
174. Which parameters must a constructor accept if the class implements
ISerializable? (Choose all that apply.)
A. SerializationInfo
B. Formatter
C. StreamingContext
D. ObjectManager
Answers: A and C
175. Which event would you use to run a method immediately before
deserialization occurs?
A. OnSerializing
B. OnDeserializing
C. OnSerialized
D. OnDeserialized
Answer: B
176. Which event would you use to run a method immediately after serialization
occurs?
A. OnSerializing
B. OnDeserializing
C. OnSerialized
D. OnDeserialized
Answer: C
177. Which of the following are requirements for a method that is called in
response to a serialization event? (Choose all that apply.)
A. Accept a StreamingContext object as a parameter.
B. Accept a SerializationInfo object as a parameter.
C. Return void.
D. Return a StreamingContext object.
Answers: A and C
178. Which of the following methods would you use to draw a square with a
solid color?
A. Graphics.DrawLines
B. Graphics.DrawRectangle
C. Graphics.DrawPolygon
D. Graphics.DrawEllipse
E. Graphics.FillRectangle
F. Graphics.FillPolygon
G. Graphics.FillEllipse
Answer: E
179. Which of the following methods would you use to draw an empty triangle?
A. Graphics.DrawLines
B. Graphics.DrawRectangle
C. Graphics.DrawPolygon
D. Graphics.DrawEllipse
E. Graphics.FillRectangle
F. Graphics.FillPolygon
G. Graphics.FillEllipse
Answer: C
180. Which of the following classes is required to draw an empty circle?
(Choose all that apply.)
A. System.Drawing.Graphics
B. System.Drawing.Pen
C. System.Drawing.Brush
D. System.Drawing.Bitmap
Answers: A and B
181. Which of the following brush classes would you use to create a solid
rectangle that is red at the top and gradually fades to white towards the bottom?
A. System.Drawing.Drawing2D.HatchBrush
B. System.Drawing.Drawing2D.LinearGradientBrush
C. System.Drawing.Drawing2D.PathGradientBrush
D. System.Drawing.SolidBrush
E. System.Drawing.TextureBrush
Answer: B
182. What type of line would the following code sample draw?
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Red, 10);
p.StartCap = LineCap.Flat;
p.EndCap = LineCap.ArrowAnchor;
g.DrawLine(p, 50, 50, 400, 50);
A. An arrow pointing up
B. An arrow pointing down
C. An arrow pointing left
D. An arrow pointing right
Answer: D
183. Which of the following classes could you use to display a JPEG image from
an existing file in a form? (Choose all that apply.)
A. System.Drawing.Image
B. System.Drawing.Bitmap
C. System.Drawing.Imaging.Metafile
D. System.Windows.Forms.PictureBox
Answers: A and B
184. How can you draw a black border around a JPEG image that you have
saved to disk, and then save the updated image back to the disk?
A. Create a Graphics object by loading the JPEG image from disk. Draw the
border by calling Graphics.DrawRectangle. Finally, save the updated image
by calling Graphics.Save.
B. Create a Bitmap object by loading the JPEG image from disk. Draw the border
by calling Bitmap.DrawRectangle. Finally, save the updated image by
calling Bitmap.Save.
C. Create a Bitmap object by loading the JPEG image from disk. Create a
Graphics object by calling Graphics.FromImage. Draw the border by calling
Graphics.DrawRectangle. Finally, save the updated image by calling Bitmap.
Save.
D. Create a Bitmap object by loading the JPEG image from disk. Create a
Graphics object by calling Bitmap.CreateGraphics. Draw the border by calling
Graphics.DrawRectangle. Finally, save the updated image by calling Bitmap.
Save.
Answer: C
185. Which format should you choose to save a photograph that could be
opened by a wide variety of applications?
A. ImageFormat.Bmp
B. ImageFormat.Gif
C. ImageFormat.Jpeg
D. ImageFormat.Png
Answer: C
186. Which format should you choose to save a pie chart that could be opened
by a wide variety of applications?
A. ImageFormat.Bmp
B. ImageFormat.Gif
C. ImageFormat.Jpeg
D. ImageFormat.Png
Answer: B
187. What are the steps for adding text to an image?
A. Create a Graphics object and a string object. Then call string.Draw.
B. Create a Graphics object, a Font object, and a Brush object. Then call Graphics
.DrawString.
C. Create a Graphics object, a Font object, and a Pen object. Then call Graphics
.DrawString.
D. Create a Bitmap object, a Font object, and a Brush object. Then call Bitmap
.DrawString.
Answer: B
188. Which of the following is a class would you need to create an instance of to
specify that a string should be centered when drawn?
A. StringFormat
B. StringAlignment
C. FormatFlags
D. LineAlignment
Answer: A
189. Which of the following commands would cause a string to be flush left?
A. StringFormat.LineAlignment = Near
B. StringFormat.LineAlignment = Far
C. StringFormat.Alignment = Near
D. StringFormat.Alignment = Far
Answer: C
190. What type of object is required when starting a thread that requires a single
parameter?
A. ThreadStart delegate
B. ParameterizedThreadStart delegate
C. SynchronizationContext class
D. ExecutionContext class
Answer: B
191. What method stops a running thread?
A. Thread.Suspend
B. Thread.Resume
C. Thread.Abort
D. Thread.Join
Answer: C
192. Assuming there is not a writer lock in place, how many readers can
simultaneously read data with a ReaderWriterLock?
A. 0
B. 1
C. 10
D. Unlimited
Answer: D
193. Which of the following can be used to synchronize threads across
AppDomain and process boundaries? (Choose all that apply)
A. Monitor class
B. Mutex class
C. Semaphore class
D. C#’s lock or Visual Basic’s SyncLock keyword
Answers: B and C
194. What method of the ThreadPool class is used to have the ThreadPool run
some specified code on threads from the pool? (Choose all that apply.)
A. ThreadPool.RegisterWaitForSingleObject
B. ThreadPool.QueueUserWorkItem
C. ThreadPool.UnsafeRegisterWaitForSingleObject
D. ThreadPool.UnsafeQueueUserWorkItem
Answers: B and D
195. How do you temporarily stop a Timer from firing?
Answer: B
196. Which of the following are valid reasons to create an application domain?
(Choose all that apply.)
A. It is the only way to launch a separate process.
B. You can remove the application domain to free up resources.
C. Application domains improve performance.
D. Application domains provide a layer of separation and security.
Answers: B and D
197. Which of the following are valid ways to run an assembly within an
application domain? (Choose all that apply.)
A. AppDomain.CreateDomain
B. AppDomain.ExecuteAssembly
C. AppDomain.ExecuteAssemblyByName
D. AppDomain.ApplicationIdentity
Answers: B and C
198. Which command would you use to close the application domain in the
following code sample?
// C#
AppDomain d = AppDomain.CreateDomain("New Domain");
d.ExecuteAssemblyByName("MyAssembly");
A. d.DomainUnload()
B. d = null
C. d.Unload()
D. AppDomain.Unload(d)
Answer: D
199. How does the runtime use evidence when creating an application domain?
A. To determine the priority at which the process should run
B. To identify the author of the assembly
C. To determine which privileges the assembly should receive
D. To track the actions of the assembly for audit purposes
Answer: C
200. Which of the following code samples runs an assembly as if it were located
on the Internet? (Choose all that apply.)
A.
object [] hostEvidence = {new Zone(SecurityZone.Internet)};
Evidence e = new Evidence(hostEvidence, null);
AppDomain d = AppDomain.CreateDomain("MyDomain", e);
d.ExecuteAssembly("Assembly.exe");
B.
object [] hostEvidence = {new Zone(SecurityZone.Internet)};
AppDomain d = AppDomain.CreateDomain("MyDomain");
Evidence e = new Evidence(hostEvidence, null);
d.Evidence = e;
d.ExecuteAssembly("Assembly.exe");
C.
AppDomain myDomain = AppDomain.CreateDomain("MyDomain");
myDomain.ExecuteAssembly("Assembly.exe", new Zone(SecurityZone.Internet));
D.
Evidence e = new Evidence();
e.AddHost(new Zone(SecurityZone.Internet));
AppDomain myDomain = AppDomain.CreateDomain("MyDomain");
myDomain.ExecuteAssembly("Assembly.exe", e);
Answers: A and D
201. How can you set the base directory for an application in an application
domain?
A. Create an instance of the AppDomain class, and then set the Dynamic-
Directory property.
B. Create an instance of the AppDomain class, and then set the BaseDirectory
property.
C. Create an instance of the AppDomainSetup class, and then set the Dynamic-
Base property. Pass the AppDomainSetup object to the AppDomain constructor.
D. Create an instance of the AppDomainSetup class, and then set the Application-
Base property. Pass the AppDomainSetup object to the AppDomain constructor
Answer: D
202. You need to notify the user if your assembly is running without the ability
to use HTTP to download assemblies. How can you determine whether you have
that permission?
A. Examine AppDomain.CurrentDomain.SetupInformation.DisallowCodeDownload.
B. Examine AppDomain.CurrentDomain.DisallowCodeDownload.
C. Examine AppDomain.CurrentDomain.SetupInformation.DisallowPublisherPolicy.
D. Examine AppDomain.CurrentDomain.DisallowPublisherPolicy.
Answer: A
203. Which account type should you choose to minimize security risks?
A. LocalService
B. NetworkService
C. LocalSystem
D. User
Answer: A
204. Which account type should you choose to minimize the possibility of
problems caused by overly restrictive permissions on the local computer?
A. LocalService
B. NetworkService
C. LocalSystem
D. User
Answer: C
205. Which of the following are valid ways to install a service on a computer?
(Choose all that apply.)
A. Add a shortcut to your assembly to the user’s Startup group.
B. Use InstallUtil to install your service.
C. Configure Scheduled Tasks to launch your assembly upon startup.
D. Use Visual Studio to create an installer for your service.
Answers: B and D
206. Which tools can you use to change the user account for a service after the
service is installed?
A. My Computer
B. Computer Management
C. Net
D. Microsoft .NET Framework 2.0 Configuration
Answer: B
207. Which code segment shows the best way to retrieve the “Foo” section of
the following configuration file?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Foo" value="Hello World!"/>
</appSettings>
</configuration>
A.
NameValueCollection AllAppSettings = ConfigurationManager.AppSettings;
Console.WriteLine(AllAppSettings["Hello World!"]);
B.
Console.WriteLine(ConfigurationSettings.AppSettings["Foo"]);
C.
NameValueCollection AllAppSettings = ConfigurationManager.AppSettings;
Console.WriteLine(AllAppSettings[5]);
D.
NameValueCollection AllAppSettings = ConfigurationManager.AppSettings;
Console.WriteLine(AllAppSettings["Foo"]);
Answer: D
208. What will happen if you try to use the following section of code to store a
connection string?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<SqlConnectionStrings>
<clear/>
<add name="AdventureWorksString"
providerName="System.Data.SqlClient"
connectionString="Data Source=localhost;Initial
Catalog=AdventureWorks;
Integrated Security=true"/>
</ SqlConnectionStrings >
</configuration>
A. There is no problem with this file, and the connection string values can be
retrieved without any issues.
B. The <clear/> tag is unnecessary because there is only one connection
string, and this tag will cause the file not to parse.
C. As long as you use the SqlConnectionStrings property of the Configuration-
Manager object, it will retrieve the value correctly.
D. There is no predefined property for SqlConnectionStrings, so the file will not
process correctly. If SqlConnectionStrings were changed to connectionStrings,
everything would work properly.
Answer: D
209. Which of the following objects or interfaces is the best solution to provide
customized configuration manipulation? (Choose all that apply.)
A. IConfigurationSectionHandler
B. ConfigurationValidatorBase
C. IConfigurationSystem
D. ApplicationSettingsBase
Answer: D
210. What base class should you derive from when creating custom
applications?
A. The InstallContext class
B. The InstallerCollection class
C. The ManagedInstallerClass class
D. The Installer class
Answer: D
211. You want to create an installation that, in the event of failure, undoes
everything it has done so far. Which of the following mechanisms accomplishes
that task?
Answer: A
212. What visual tool does Visual Studio 2005 use to allow developers to edit
and manage registry keys?
A. The Custom Actions view
B. The File System view
C. The Registry Editor view
D. The Registry view
Answer: D
213. What can be handled by using the .NET Framework 2.0 Configuration tool?
(Choose all that apply.)
A. View All running processes and manage their permission sets
B. View All running services and manage their operation
C. ViewAll configured applications
D. View All assemblies in the global assembly cache (GAC)
Answers: C and D
214. Which of the following items can be created by using the .NET Framework
2.0 Configuration tool?
A. Permission sets
B. Code sets
C. Assembly sets
D. Application sets
Answer: A
215. Which methods of the Configuration class are valid ways to open a
configuration file? (Choose all that apply.)
A. OpenExeConfiguration
B. OpenMachineConfiguration
C. OpenMappedExeConfiguration
D. OpenMappedMachineConfiguration
Answers: A, B, C, and D
216. What method causes settings to be read from an
IconfigurationSectionHandler object?
A. Create
B. ReadSection
C. GetConfig
D. GetAppSettings
Answer: A