Written by Riley Perry from Distributed Development
OK – here we go,
the answers to the first 173.
1. Name 10 C# keywords.
abstract, event, new, struct,
explicit, null, base, extern, object, this
2. What is public accessibility?
There are no access restrictions.
3. What is protected accessibility?
Access is restricted to types derived
from the containing class.
4. What is internal accessibility?
A member marked internal is only accessible from files within the
same assembly.
5. What is protected internal accessibility?
Access is restricted to types derived
from the containing class or from files within the same assembly.
6. What is private accessibility?
Access is restricted to within the
containing class.
7. What is the default accessibility for a class?
internal for a top level class,
private for a nested one.
8. What is the default accessibility for members of an
interface?
public
9. What is the default accessibility for members of a
struct?
private
10. Can the members of an interface be private?
No.
11. Methods must declare a return type, what is the keyword used
when nothing is returned from the method?
void
12. Class methods to should be marked with what keyword?
static
13. Write some code using interfaces, virtual methods, and an
abstract class.
using System;
public interface
Iexample1
{
int
MyMethod1();
}
public interface
Iexample2
{
int
MyMethod2();
}
public abstract
class ABSExample : Iexample1, Iexample2
{
public
ABSExample()
{
System.Console.WriteLine("ABSExample
constructor");
}
public
int MyMethod1()
{
return 1;
}
public
int MyMethod2()
{
return 2;
}
public
abstract void
MyABSMethod();
}
public class
VIRTExample : ABSExample
{
public
VIRTExample()
{
System.Console.WriteLine("VIRTExample
constructor");
}
public
override void
MyABSMethod()
{
System.Console.WriteLine("Abstract
method made concrete");
}
public
virtual void
VIRTMethod1()
{
System.Console.WriteLine("VIRTMethod1
has NOT been overridden");
}
public
virtual void
VIRTMethod2()
{
System.Console.WriteLine("VIRTMethod2
has NOT been overridden");
}
}
public class
FinalClass : VIRTExample
{
public
override void
VIRTMethod2()
{
System.Console.WriteLine("VIRTMethod2
has been overridden");
}
}
14. A class can have many mains, how does this work?
Only one of them is run, that is the
one marked (public) static, e.g:
public static
void Main(string[]
args)
{
//
//
TODO: Add code to start application here
//
}
private void
Main(string[] args, int
i)
{
}
15. Does an object need to be made to run main?
No
16. Write a hello world console application.
using System;
namespace Console1
{
class
Class1
{
[STAThread] // No longer needed
static void Main(string[] args)
{
Console.WriteLine("Hello
world");
}
}
}
17. What are the two return types for main?
void and int
18. What is a reference parameter?
Reference parameters reference the original object
whereas value parameters make a local copy and do not affect the original. Some
example code is shown:
using System;
namespace Console1
{
class
Class1
{
static void Main(string[] args)
{
TestRef
tr1 = new TestRef();
TestRef
tr2 = new TestRef();
tr1.TestValue
= "Original value";
tr2.TestValue
= "Original value";
int tv1 = 1;
int tv2 = 1;
TestRefVal(ref tv1, tv2, ref
tr1, tr2);
Console.WriteLine(tv1);
Console.WriteLine(tv2);
Console.WriteLine(tr1.TestValue);
Console.WriteLine(tr2.TestValue);
Console.ReadLine();
}
static public void TestRefVal(ref int tv1Parm,
int tv2Parm,
ref TestRef tr1Parm,
TestRef
tr2Parm)
{
tv1Parm = 2;
tv2Parm
= 2;
tr1Parm.TestValue
= "New value";
tr2Parm.TestValue
= "New value";
}
}
}
class TestRef
{
public
string TestValue;
}
The output for this is:
2
1
New value
New value
19. What is an out parameter?
An out parameter allows an instance of a parameter
object to be made inside a method. Reference parameters must be initialised but
out gives a reference to an uninstanciated object.
20. Write code to show how a method can accept a varying
number of parameters.
using System;
namespace Console1
{
class
Class1
{
static void Main(string[] args)
{
ParamsMethod(1,"example");
ParamsMethod(1,2,3,4);
Console.ReadLine();
}
static void
ParamsMethod(params object[]
list)
{
foreach (object o in list)
{
Console.WriteLine(o.ToString());
}
}
}
}
21. What is an overloaded method?
An overloaded method has multiple signatures that are
different.
22. What is recursion?
Recursion is when a method calls itself.
23. What is a constructor?
A constructor performs initialisation for an object
(including the struct type) or class.
24. If I have a constructor with a parameter, do I need to
explicitly create a default constructor?
Yes
25. What is a destructor?
A C# destuctor is not like a C++ destructor. It is
actually an override for Finalize(). This is called when the garbage collector
discovers that the object is unreachable. Finalize() is called before any
memory is reclaimed.
26. Can you use access modifiers with destructors?
No
27. What is a delegate?
A delegate in C# is like a function pointer in C or C++. A delegate is a variable that calls a method
indirectly, without knowing its name. Delegates can point to static or/and
member functions. It is also possible to use a multicast delegate to point to multiple
functions.
28. Write some code to use a delegate.
using System;
namespace Console1
{
class
Class1
{
delegate void
myDelegate(int parameter1);
static void Main(string[] args)
{
MyClass
myInstance = new MyClass();
myDelegate
d = new myDelegate(myInstance.AMethod);
d(1);
// <--- Calling function without knowing its name.
Test2(d);
Console.ReadLine();
}
static void
Test2(myDelegate d)
{
d(2);
// <--- Calling function without knowing its name.
}
}
class
MyClass
{
public void AMethod(int param1)
{
Console.WriteLine(param1);
}
}
}
using System;
namespace Console1
{
class
Class1
{
delegate void
myDelegate(int parameter1);
static void
AStaticMethod(int param1)
{
Console.WriteLine(param1);
}
static void Main(string[] args)
{
MyClass
myInstance = new MyClass();
myDelegate
d = null;
d +=
new myDelegate(myInstance.AMethod);
d +=
new myDelegate(AStaticMethod);
d(1);
//both functions will be run.
Console.ReadLine();
}
}
class
MyClass
{
public void AMethod(int param1)
{
Console.WriteLine(param1);
}
}
}
29. What is a delegate useful for?
The main reason we use delegates is
for
use in event driven programming.
30. What is an event?
See 32
31. Are events synchronous of asynchronous?
Asynchronous
32. Events use a publisher/subscriber model. What is that?
Objects publish events to which other
applications subscribe. When the publisher
raises an event all subscribers to that event are notified.
33. Can a subscriber subscribe to more than one publisher?
Yes, also - here's some code for a publisher with multiple subscribers.
using System;
namespace Console1
{
class
Class1
{
delegate void
myDelegate(int parameter1);
static event
myDelegate myEvent;
static void
AStaticMethod(int param1)
{
Console.WriteLine(param1);
}
static void Main(string[] args)
{
MyClass
myInstance = new MyClass();
myEvent
+= new myDelegate(myInstance.AMethod);
myEvent
+= new myDelegate(AStaticMethod);
myEvent(1);
//both functions will be run.
Console.ReadLine();
}
}
class
MyClass
{
public void AMethod(int param1)
{
Console.WriteLine(param1);
}
}
}
Another example:
using System;
using System.Threading;
namespace EventExample
{
public
class Clock
{
public delegate void TwoSecondsPassedHandler(object
clockInstance, TimeEventArgs time);
//The clock publishes an event that others subscribe to
public event
TwoSecondsPassedHandler TwoSecondsPassed;
public void Start()
{
while(true)
{
Thread.Sleep(2000);
//Raise event
TwoSecondsPassed(this, new
TimeEventArgs(1));
}
}
}
public
class TimeEventArgs : EventArgs
{
public TimeEventArgs(int
second)
{
seconds
+= second;
instanceSeconds
= seconds;
}
private static int seconds;
public int
instanceSeconds;
}
public
class MainClass
{
static void Main(string[] args)
{
Clock
cl = new Clock();
// add some subscribers
cl.TwoSecondsPassed
+= new
Clock.TwoSecondsPassedHandler(Subscriber1);
cl.TwoSecondsPassed
+= new
Clock.TwoSecondsPassedHandler(Subscriber2);
cl.Start();
Console.ReadLine();
}
public static void Subscriber1(object
clockInstance, TimeEventArgs time)
{
Console.WriteLine("Subscriber1:"
+ time.instanceSeconds);
}
public static void Subscriber2(object
clockInstance, TimeEventArgs time)
{
Console.WriteLine("Subscriber2:"
+ time.instanceSeconds);
}
}
}
34. What is a value type and a reference type?
A reference type is known by a reference to a memory
location on the heap.
A
value type is directly stored in a memory location on the stack. A reference
type is essentially a pointer, dereferencing the pointer takes more time than
directly accessing the direct memory location of a value type.
35. Name 5 built in types.
Bool, char, int, byte, double
36. string is an alias for what?
System.String
37. Is string Unicode, ASCII, or something else?
Unicode
38. Strings are immutable, what does this mean?
Any changes to that string are in fact copies.
39. Name a few string properties.
trim, tolower, toupper,
concat, copy, insert, equals, compare.
40. What is boxing and unboxing?
Converting a value type (stack->heap) to a
reference type (heap->stack), and vise-versa.
41. Write some code to box and unbox a value type.
// Boxing
int i = 4;
object o = i;
// Unboxing
i = (int) o;
42. What is a heap and a stack?
There are 2 kinds of heap – 1: a chunk of memory where
data is stored and 2: a tree based data structure. When we talk about the heap
and the stack we mean the first kind of heap.
The stack is a LIFO data structure that stores variables and flow
control information. Typically each thread will have its own stack.
43. What is a pointer?
A pointer is a reference to a memory
address.
44. What does new do in terms of objects?
Initializes an object.
45. How do you dereference an object?
Set it equal to null.
46. In terms of references, how do == and != (not overridden)
work?
They check to see if the references both point to the
same object.
47. What is a struct?
Unlike in C++ a struct is not a class – it is a value
type with certain restrictions. It is usually best to use a struct to represent
simple entities with a few variables. Like a Point for example which contains
variables x and y.
48. Describe 5 numeric value types ranges.
sbyte -128 to 127, byte 0 – 255,
short -32,768 to 32,767, int -2,147,483,648 to 2,147,483,647, ulong 0 to
18,446,744,073,709,551,615
49. What is the default value for a bool?
false
50. Write code for an enumeration.
public enum animals {Dog=1,Cat,Bear};
51. Write code for a case statement.
switch (n)
{
case
1:
x=1;
break;
case
2:
x=2;
break;
default:
goto case 1;
}
52. Is a struct stored on the heap or stack?
Stack
53. Can a struct have methods?
Yes
54. What is checked { } and unchecked { }?
By default C# does not check
for overflow (unless using constants), we can use checked to raise an
exception. E.g.:
static short
x = 32767; //
Max short value
static short
y = 32767;
// Using a checked expression
public static
int myMethodCh()
{
int
z = 0;
try
{
z = checked((short)(x + y));
//z = (short)(x +
y);
}
catch
(System.OverflowException e)
{
System.Console.WriteLine(e.ToString());
}
return
z; // Throws
the exception OverflowException
}
This code will raise an exception, if we remove unchecked as in:
//z =
checked((short)(x + y));
z = (short)(x +
y);
Then the cast will raise no overflow exception and z will be assigned
–2. unchecked can be used in the opposite way, to say avoid compile time errors
with constanst overflow. E.g. the following will cause a compiler error:
const short
x = 32767; //
Max short value
const short
y = 32767;
public static
int myMethodUnch()
{
int
z = (short)(x
+ y);
return
z; //
Returns -2
}
The following will not:
const short
x = 32767; //
Max short value
const short
y = 32767;
public static
int myMethodUnch()
{
int
z = unchecked((short)(x + y));
return z; // Returns -2
}
55. Can C# have global overflow checking?
Yes
56. What is explicit vs. implicit conversion?
When converting from a smaller numeric type into a
larger one the cast is implicit. An example of when an explicit cast is needed is
when a value may be truncated.
57. Give examples of both of the above.
// Implicit
short shrt = 400;
int intgr = shrt;
// Explicit
shrt = (short)
intgr;
58. Can assignment operators be overloaded directly?
No
59. What do operators is and as do?
as acts is like a cast but returns a null on
conversion failure. Is comares an
object to a type and returns a boolean.
60. What is the difference between the new operator and
modifier?
The new operator creates an instance of a class
whereas the new modifier is used to declare a method with the same name as a
method in one of the parent classes.
61. Explain sizeof and typeof.
typeof obtains the System.Type
object for a type and sizeof obtains the size of a type.
62. What doe the stackalloc operator do?
Allocate a block of memory
on the stack (used in unsafe mode).
63. Contrast ++count vs. count++.
Some operators have temporal
properties depending on their placement. E.g.
double x;
x = 2;
Console.Write(++x);
x = 2;
Console.Write(x++);
Console.Write(x);
Returns
323
64. What are the names of the three types of operators?
Unary, binary, and
conversion.
65. An operator declaration must include a public and static
modifier, can it have other modifiers?
No
66. Can operator parameters be reference parameters?
No
67. Describe an operator from each of these categories:
Arithmetic: +
Logical (boolean and bitwise): &
String concatenation: +
Increment, decrement: ++
Shift: >>
Relational: ==
Assignment: =
Member access: .
Indexing: []
Cast: ()
Conditional: ?:
Delegate concatenation and removal: +
Object creation: new
Type information: as
Overflow exception control: checked
Indirection and Address: *
68. What does operator order of
precedence mean?
Certain operators are evaluated before others.
Brackets help to avoid confusion.
69. What is special about the declaration of relational
operators?
Relational operators must be
declared in pairs.
70. Write some code to overload an operator.
class TempleCompare
{
public
int templeCompareID;
public
int templeValue;
public
static bool operator == (TempleCompare x, TempleCompare y) { return (x.templeValue == y.templeValue); }
public
static bool operator != (TempleCompare x, TempleCompare y) { return !(x == y); }
public
override bool
Equals(object o)
{
//
check types match
if
(o == null || GetType()!= o.GetType()) return false;
TempleCompare t =
(templeCompare) o;
return (this.templeCompareID
== t.templeCompareID) && (this.templeValue
== t.templeValue);
}
public
override int
GetHashCode() { return templeCompareID; }
}
71. What operators cannot be overloaded?
=, ., ?:, ->, new, is, sizeof,
typeof
72. What is an exception?
A runtime
error.
73. Can C# have multiple catch blocks?
Yes
74. Can break exit a finally block?
No
75. Can Continue exit a finally block?
No
76. Write some try…catch…finally code.
//
try-catch-finally
using System;
public class TCFClass
{
public
static void
Main ()
{
try
{
throw new
NullReferenceException();
}
catch(NullReferenceException
e)
{
Console.WriteLine("{0}
exception 1.", e);
}
catch
{
Console.WriteLine("exception
2.");
}
finally
{
Console.WriteLine("finally
block.");
}
}
}
77. What are expression and declaration statements?
·
Expression – produces a
value e.g. blah = 0
·
Declaration – e.g. int
blah;
78. A block contains a statement list {s1;s2;} what is an
empty statement list?
{;}
79. Write some if… else if… code.
int n=4;
if (n==1)
Console.WriteLine("n=1");
else if
(n==2)
Console.WriteLine("n=2");
else if
(n==3)
Console.WriteLine("n=3");
else
Console.WriteLine("n>3");
80. What is a dangling else?
if (n>0)
if
(n2>0)
Console.Write("Dangling
Else")
else
81. Is switch case sensitive?
Yes
82. Write some code for a for loop
for (int i = 1; i <= 5; i++)
Console.WriteLine(i);
83. Can you increment multiple variables in a for loop control?
Yes – e.g. for (int i = 1; j = 2;i <= 5 ;i++ ;j=j+2)
84. Write some code for a while loop.
int n = 1;
while (n < 6)
{
Console.WriteLine("Current
value of n is {0}", n);
n++;
}
85. Write some code for do… while.
int x;
int y = 0;
do
{
x = y++;
Console.WriteLine(x);
}
while(y < 5);
86. Write some code that declares an array on ints, assigns
the values: 0,1,2,5,7,8,11 to that array and use a foreach to do something with
those values.
int x = 0, y = 0;
int[] arr = new int [] {0,1,2};
foreach (int
i in arr)
{
if
(i%2 == 0)
x++;
else
y++;
}
87. Write some code for a custom collection class.
using System;
using System.Collections;
public class
Items : IEnumerable
{
private
string[] contents;
public
Items(string[] contents)
{
this.contents = contents;
}
public
IEnumerator GetEnumerator()
{
return new
ItemsEnumerator(this);
}
private
class ItemsEnumerator : IEnumerator
{
private int location
= -1;
private Items i;
public ItemsEnumerator(Items i)
{
this.i = i;
}
public bool
MoveNext()
{
if (location < i.contents.Length - 1)
{
location++;
return true;
}
else
{
return false;
}
}
public void Reset()
{
location
= -1;
}
public object Current
{
get
{
return i.contents[location];
}
}
}
static
void Main()
{
// Test
string[] myArray =
{"a","b","c"};
Items items = new Items(myArray);
foreach (string item in items)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
88. Describe Jump statements: break, continue, and goto.
Break terminates a loop or switch.
Continue jumps to the next iteration of an enclosing iteration statement. Goto jumps to a
labelled statement.
89. How do you declare a constant?
public const int c1 = 5;
90. What is the default index of an array?
0
91. What is array rank?
The dimension of the array.
92. Can you resize an array at runtime?
No
93. Does the size of an array need to be defined at compile
time.
No
94. Write some code to implement a multidimensional array.
int[,] b = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {8, 9}};
95. Write some code to implement a jagged array.
// Declare the array of two elements:
int[][] myArray = new int[2][];
// Initialize the elements:
myArray[0] = new int[5] {1,3,5,7,9};
myArray[1] = new int[4] {2,4,6,8};
96. What is an ArrayList?
A data structure from System.Collections
that can resize itself.
97. Can an ArrayList be ReadOnly?
Yes
98. Write some code that uses an ArrayList.
ArrayList list = new ArrayList();
list.Add("Hello");
list.Add("World");
99. Write some code to implement an indexer.
using System;
namespace Console1
{
class
Class1
{
static void Main(string[] args)
{
MyIndexableClass
m = new MyIndexableClass();
Console.WriteLine(m[0]);
Console.WriteLine(m[1]);
Console.WriteLine(m[2]);
Console.ReadLine();
}
}
class
MyIndexableClass
{
private string
[]myData = {"one","two","three"};
public string this [int i]
{
get
{
return myData[i];
}
set
{
myData[i]
= value;
}
}
}
}
100. Can properties have an access modifier?
Yes
101. Can properties hide base class members of the same name?
Yes
102. What happens if you make a property static?
They become class properties.
103. Can a property be a ref or out parameter?
A property is not classified as a variable – it can’t be ref or out
parameter.
104. Write some code to declare and use properties.
// instance
public string
InstancePr
{
get
{
return a;
}
set
{
a = value;
}
}
//read-only static
public static
int ClassPr
{
get
{
return b;
}
}
105. What is an accessor?
An accessor contains executable statements associated with getting or
setting properties.
106. Can an interface have properties?
Yes
107. What is early and late binding?
Late binding is using System.object instead of explicitly declaring a class (which is early binding).
108. What is polymorphism
Polymorphism is the ability
to implement the same operation many times. Each derived method implements the
operation inherited from the base class in its own way.
109. What is a nested class?
A class declare within a class.
110. What is a namespace?
A namespace declares a scope which is useful for
organizing code and to distinguish one type from another.
111. Can nested classes use any of the 5 types of
accessibility?
Yes
112. Can base constructors can be private?
Yes
113. object is an alias for what?
System.Object
114. What is reflection?
Reflection allows us to analyze an assembly’s metadata
and it gives us a mechanism to do late binding.
115. What namespace would you use for reflection?
System.Reflection
116. What does this do? Public Foo() : this(12, 0, 0)
Calls another constructor in the
list
117. Do local values get garbage collected?
They die when they are
pulled off the stack (go out of scope).
118. Is object destruction deterministic?
No
119. Describe garbage collection (in simple terms).
Garbage collection eliminates uneeded objects.
120. What is the using statement for?
The
using statement defines a scope at the end of which an object will be disposed.
121. How do you refer to a member in the base class?
To refer to a member in the
base class use:return base.NameOfMethod().
122. Can you derive from a struct?
No
123. Does C# supports multiple inheritance?
No
124. All classes derive from what?
System.Object
125. Is constructor or destructor inheritance explicit or
implicit? What does this mean?
Constructor or destructor
inheritance is explicit…. Public Extended : base()à this is called the constructor initializer.
126. Can different assemblies share internal access?
No
127. Does C# have “friendship”?
Not before C# 2.0
128. Can you inherit from multiple interfaces?
Yes
129. In terms of constructors, what is the difference between:
public MyDerived() : base() an public MyDerived() in a child class?
Nothing
130. Can abstract methods override virtual methods?
Yes
131. What keyword would you use for scope name clashes?
this
132. Can you have nested namespaces?
Yes
133. What are attributes?
Attributes are declarative tags which can
be used to mark certain entities (like methods for example).
134. Name 3 categories of predefined attributes.
COM Interop, Transaction,
Visual Designer Component Builder
135. What are the 2 global attributes.
assembly and module.
136. Why would you mark something as Serializable?
To show that the marked type can be serialized.
137. Write code to define and use your own custom attribute.
(From MSDN)
//
cs_attributes_retr.cs
using System;
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct,
AllowMultiple=true)]
public class Author : Attribute
{
public
Author(string name)
{
this.name
= name; version = 1.0;
}
public
double version;
string
name;
public
string GetName()
{
return
name;
}
}
138. List some custom attribute scopes and possible targets.
Assembly
– assembly
Class
– type
Delegate
- type, return
139. List some compiler directives?
#if
#else
#elif
#endif
#define
#undef
#warning
#error
#line
#region
#endregion
140. What is a thread?
A thread is a the
entity within a process that Windows schedules for execution. A thread has:
Threads sometimes have their
own security context.
141. Do you spin off or spawn a thread?
Spin off
142. What is the volatile keyword used for?
It indicates a field can be modified
by an external entity (thread, OS, etc.).
143. Write code to use threading and the lock keyword.
using System;
using System.Threading;
namespace ConsoleApplication4
{
class
Class1
{
[STAThread]
static void Main(string[] args)
{
ThreadClass
tc1 = new ThreadClass(1);
ThreadClass
tc2 = new ThreadClass(2);
Thread
oT1 = new Thread(new
ThreadStart(tc1.ThreadMethod));
Thread
oT2 = new Thread(new
ThreadStart(tc2.ThreadMethod));
oT1.Start();
oT2.Start();
Console.ReadLine();
}
}
class
ThreadClass
{
private static object lockValue = "dummy";
public int
threadNumber;
public ThreadClass(int
threadNumber)
{
this.threadNumber = threadNumber;
}
public void
ThreadMethod()
{
for (;;)
{
lock(lockValue)
{
Console.WriteLine(threadNumber
+ " working");
Thread.Sleep(1000);
}
}
}
}
}
144. What is Monitor?
Monitor is a class that has various functions for
thread synchronization.
145. What is a semaphore?
A resource management, synchronization, and locking
tool.
146. What mechanisms does C# have for the readers, writers
problem?
System.Threading.ReaderWriterLock
which has methods AcquireReaderLock, ReleaseReaderLock, AcquireWriterLock, and
ReleaseWriterLock
147. What is Mutex?
A Mutex object is used to guarantee only one thread
can access a critical resource an any one time.
148. What is an assembly?
Assemblies contain logical units of code in MSIL,
metadata, and usually a manifest. Assemblies can be signed and the can dome in
the form of a DLL or EXE.
149. What is a DLL?
A set of callable functions,
which can be dynamically loaded.
150. What is an assembly identity?
Assembly identity is name,
version number, and optional culture, and optional public key to guarantee
uniqueness.
151. What does the assembly manifest contain?
Assembly manifest lists all
names of public types and resources and their locations in the assembly.
152. What is IDLASM used for?
Use IDLASM to see
assembly internals. It disassembles into MSIL.
153. Where are private assemblies stored?
Same folder as exe
154. Where are shared assemblies stored?
The GAC
155. What is DLL hell?
DLLs,
VBX or OCX files being unavailable or in the wrong versions. Applicatioins
using say these older DLLs expect some behaviour which is not present.
156. In terms of assemblies, what is side-by-side execution?
An app can be configured to use different versions of an assembly
simultaneously.
157. Name and describe 5 different documentation tags.
/// <value></value>
/// <example></example>
/// <exception
cref=""></exception>
/// <include
file='' path='[@name=""]'/>
/// <param
name="args"></param>
/// <paramref
name=""/>
/// <permission
cref=""></permission>
/// <remarks>
/// </remarks>
/// <summary>
/// <c></c>
/// <code></code>
/// <list
type=""></list>
/// <see
cref=""/>
/// <seealso
cref=""/>
/// </summary>
158. What is unsafe code?
Unsafe code bypasses type safety and memory
management.
159. What does the fixed statement do?
Prevents relocation of a variable by GC.
160. How would you read and write using the console?
Console.Write,
Console.WriteLine, Console.Readline
161. Give examples of hex, currency, and fixed point console
formatting.
Console.Write("{0:X}",
250); à FA
Console.Write("{0:C}",
2.5); à $2.50
Console.Write("{0:F2}",
25); à 25.00
162. Given part of a stack trace:
aspnet.debugging.BadForm.Page_Load(Object sender, EventArgs e) +34. What does
the +34 mean?
It is an actual offset (at the
assembly language level) – not an offset
into the IL instructions.
163. Are value types are slower to pass as method parameters?
Yes
164. How can you implement a mutable string?
System.Text.StringBuilder
165. What is a thread pool?
A thread pool is a means by which to control a number of
threads simultaneously. Thread pools give us thread reuse, rather than creating
a new thread every time.
166. Describe the CLR security model.
http://msdn.microsoft.com/msdnmag/issues/02/09/SecurityinNET/default.aspx
“Unlike the old principal-based security,
the CLR enforces security policy based on where code is coming from rather than
who the user is. This model, called code access security, makes sense in
today's environment because so much code is installed over the Internet and
even a trusted user doesn't know when that code is safe.”
167. What’s the difference between camel and pascal casing?
PascalCasing, camelCasing
168. What does marshalling mean?
http://www.dictionary.net/marshalling
“The process of
packing one or more items of data into a message buffer, prior to transmitting
that message buffer over a communication channel. The packing process not only
collects together values which may be stored in non-consecutive memory
locations but also converts data of different types into a standard
representation agreed with the recipient of the message.”
169. What is inlining?
From (Google web defintions)
“In-line expansion or inlining for short is a compiler
optimization which "expands" a function call site into the actual
implementation of the function which is called, rather than each call transferring
control to a common piece of code. This reduces overhead associated with the
function call, which is especially important for small and frequently called
functions, and it helps call-site-specific compiler optimizations, especially
constant propagation.”
170. List the differences in C# 2.0.
·
Generics
·
Iterators
·
Partial class
definitions
·
Nullable Types
·
Anonymous methods
·
:: operator
·
Static classes static
class members
·
Extern keyword
·
Accessor accessibility
·
Covariance and
Contravariance
·
Fixed size buffers
·
Fixed assemblies
·
#pragma warning
171. What are design patterns?
http://www.dofactory.com/Patterns/Patterns.aspx
“Design patterns are recurring solutions to software
design problems you find again and again in real-world application
development.”
172. Describe some common design patterns.
http://www.dofactory.com/Patterns/Patterns.aspx
Creational Patterns
Abstract Factory Creates an instance of several families of
classes
Builder Separates object construction from its representation
Factory Method Creates an instance of several derived
classes
Prototype A fully initialized instance to be copied or cloned
Singleton A class of which only a single instance can exist
Adapter Match interfaces of different classes
Bridge Separates an object’s interface from its implementation
Composite A tree structure of simple and composite objects
Decorator Add responsibilities to objects dynamically
Façade A single class that represents an entire subsystem
Flyweight A fine-grained instance used for efficient sharing
Proxy An object representing another object
Chain of Resp. A way of passing a request between a chain
of objects
Command Encapsulate a command request as an object
Interpreter A way to include language elements in a program
Iterator Sequentially access the elements of a collection
Mediator Defines simplified communication between classes
Memento Capture and restore an object's internal state
Observer A way of notifying change to a number of classes
State Alter an object's behavior when its state changes
Strategy Encapsulates an algorithm inside a class
Template Method Defer the exact steps of an algorithm to a
subclass
Visitor Defines a new operation to a class without change
173. What are the different diagrams in UML? What are they
used for?
http://www.developer.com/design/article.php/1553851