C# Flashcards

1
Q

Late and early binding

A

Early binding Or Compile time Or static binding: Assigning of object to type reference happens at compile time.

Late binding Or Run time Or Dynamic binding: Assigning of object to type reference happens at run time.

Early binding is efficient while late binding provides flexibility to programmers.

Early binding is best. Because any errors can be resolved at compile time. Late binding is at Run Time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

All .Net code have to be cls compliant

A

Not required. If you want your code to be CLS complaint use the annotation CLScompliant(true)

Answered by: Ravi Kumar on: Dec 3rd, 2011

False All .Net code need not be CLS compliant if you are going to write all modules using single .Net language. However, if you are going to use different .Net language for different modules then you…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain what are object oriented language and object based language

A

Any langauge based on encapsulation concpet and operations with the objects are called as Object Based language. Exmaple : VB is a Object based and not an Object oriented

Any langauge based on encapsulation concept and operations with the objects and also dealing with the inheritance and polymorphism are called as Object Oriented language. Exmaple : C++,C#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why strings are immutable?

A

makes it thread safe and
thus imporves performance.

1) In VB6.0 and c++ strings are simple array of bytes, but in .Net it is class System.String and is immutable.
2) A string is a sequential collection of Unicode characters, which usually is used to represent text. A String, on the other hand, is a .NET Framework class (System.String) that represents a Unicode string with a sequential collection of System.Char structure.

String is of reference type which holds an array of char.

string s = “abc”;

internally creates an array of char similar to one below

char[] s = new char[] {‘a’,’b’,’c’};

Arrays are created with definite length and it cannot be dynamically increased.

This is the reason behind immutability in string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can you store multiple data types in System.Array?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

A

The first one performs a deep copy of the array, the second one is shallow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s the .NET datatype that allows the retrieval of data by a unique key?

A

HashTable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?

A

A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Can multiple catch blocks be executed?

A

No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why is it a bad idea to throw your own exceptions?

A

Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s a delegate?

A

A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What’s a multicast delegate?

A

It’s a delegate that points to and eventually fires off several methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How’s the DLL Hell problem solved in .NET?

A

Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What’s a satellite assembly?

A

When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What namespaces are necessary to create a localized application?

A

System.Globalization, System.Resources.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s the difference between // comments, /* */ comments and /// comments?

A

Single-line, multi-line and XML documentation comments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you generate documentation from the C# file commented properly with a command-line compiler?

A

Compile it with a /doc switch.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What’s the difference between and <code> XML documentation tag?</code>

A

Single line code example and multiple-line code example.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Is XML case-sensitive?

A

Yes, so and are different elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What does assert() do?

A

In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What’s the difference between the Debug class and Trace class? Documentation looks the same.

A

Use Debug class for debug builds, use Trace class for both debug and release builds.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Why are there five tracing levels in System.Diagnostics.TraceSwitcher?

A

The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Where is the output of TextWriterTraceListener redirected?

A

To the Console or a text file depending on the parameter passed to the constructor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How do you debug an ASP.NET Web application?

A

Attach the aspnet_wp.exe process to the DbgClr debugger.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What are three test cases you should go through in unit testing?

A

Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Can you change the value of a variable while debugging a C# application?

A

Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Explain the three services model (three-tier application).

A

Presentation (UI), business (logic and underlying code) and data (from storage or other sources).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?

A

SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What’s the role of the DataReader class in ADO.NET connections?

A

It returns a read-only dataset from the data source when the command is executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What is the wildcard character in SQL? Let’s say you want to query database with LIKE for all employees whose name starts with La.

A

The wildcard character is %, the proper query with LIKE would involve ‘La%’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Explain ACID rule of thumb for transactions.

A

Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Which one is trusted and which one is untrusted?

A

Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Why would you use untrusted verificaion?

A

Web Services might use it, as well as non-Windows applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What does the parameter Initial Catalog define inside Connection String?

A

The database name to connect to.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What does Dispose method do with the connection object?

A

Deletes it from the memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

What is a pre-requisite for connection pooling?

A

Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

How can you sort the elements of the array in descending order?

A

By calling Sort() and then Reverse() methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What is the difference between Finalize() and Dispose()?

A

Dispose() is called by as an indication for an object to release any unmanaged resources it has held.
Finalize() is used for the same purpose as dispose however finalize doesn’t assure the garbage collection of an object.
Dispose() operates determinalistically due to which it is generally preferred.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Is it possible to have different access modifiers on the get/set methods of a property?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

If I return out of a try/finally in C#, does the code in the finally-clause run?

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

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?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

How does one compare strings in C#?

A

Easier in C#. Use if ((object) str1 == (object) str2) { }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

How do you mark a method obsolete?

A

[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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

How do you implement thread synchronization (Object.Wait, Notify,and CriticalSection) in C#?

A

You want the lock statement, which is the same as Monitor Enter/Exit:
lock(obj) { // code }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

What do you know about .NET assemblies?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

What’s the difference between private and shared assembly?

A

Private assembly is used inside an application only and does not have to be identified by a strong name. Shared assembly can be used by multiple applications and has to have a strong name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

What’s a strong name?

A

A strong name includes the name of the assembly, version number, culture identity, and a public key token.

48
Q

How can you tell the application to look for assemblies at the locations other than its own install?

A

Use the directive in the XML .config file for a given application.
< probing privatePath=c:\mylibs; bin\debug />
should do the trick. Or you can add additional search paths in the Properties box of the deployed application.

49
Q

Is there an equivalent of exit() for quitting a C# .NET application?

A

Yes, you can use System.Environment.Exit(int exitCode) to exit the application or Application.Exit() if it’s a Windows Forms app.

50
Q

Can you prevent your class from being inherited and becoming a base class for some other classes?

A

Yes, that is what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It is the same concept as final class in Java.

51
Q

How do I make a DLL in C#?

A

You need to use the /target:library compiler option.

52
Q

Will finally block get executed if the exception had not occurred?

A

Yes.

53
Q

Is there regular expression (regex) support available to C# developers?

A

Yes. The .NET class libraries provide support for regular expressions. Look at the documentation for the System.Text.RegularExpressions namespace.

54
Q

Is there a way to force garbage collection?

A

Yes. Set all references to null and then call System.GC.Collect(). If you need to have some objects destructed, and System.GC.Collect() doesn’t seem to be doing it for you, you can force finalizers to be run by setting all the references to the object to null and then calling System.GC.RunFinalizers().

55
Q

Does C# support properties of array types?

A
Yes. Here's a simple example: using System;
class Class1
{
private string[] MyField;
public string[] MyProperty
{
get { return MyField; }
set { MyField = value; }
}
}
class MainClass
{
public static int Main(string[] args)
{
Class1 c = new Class1();
string[] arr = new string[] {"apple", "banana"};
c.MyProperty = arr;
Console.WriteLine(c.MyProperty[0]); // "apple"
return 0;
}
}
55
Q

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?

A

Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there is no implementation in

56
Q

What is the equivalent to regsvr32 and regsvr32 /u a file in .NET development?

A

Try using RegAsm.exe. The general syntax would be: RegAsm. A good description of RegAsm and its associated switches is located in the .NET SDK docs. Just search on “Assembly Registration Tool”.

57
Q

Where is the output of TextWriterTraceListener redirected?

A

To the Console or a text file depending on the parameter passed to the constructor.

58
Q

How do I create a multilanguage, single-file assembly?

A

This is currently not supported by Visual Studio .NET.

59
Q

Why cannot you specify the accessibility modifier for methods inside the interface?

A

There is no way to restrict to a namespace. Namespaces are never units of protection. But if you’re using assemblies, you can use the ‘internal’ access modifier to restrict access to only within the assembly.

60
Q

Why do I get a syntax error when trying to declare a variable called checked?

A

The word checked is a keyword in C#.

61
Q

What is the syntax for calling an overloaded constructor within a constructor (this() and constructorname() does not compile)?

A
class B
{
    B(int i){ }
}
class C : B
{
     // call base constructor B(5)
    C() : base(5) { }
    C(int i) : this() // call C()
     { }
public static void Main() {} }
62
Q

Why do I get a “CS5001: does not have an entry point defined” error when compiling?

A
The most common problem is that you used a lowercase 'm' when defining the Main method. The correct way to implement the entry point is as follows:
class test
{
static void Main(string[] args) {}
}
63
Q

What does the keyword virtual mean in the method definition?

A

The method can be over-ridden.

64
Q

What optimizations does the C# compiler perform when you use the /optimize+ compiler option?

A

The following is a response from a developer on the C# compiler team:
We get rid of unused locals (i.e., locals that are never read, even if assigned).
We get rid of unreachable code.
We get rid of try-catch w/ an empty try.
We get rid of try-finally w/ an empty try (convert to normal code…).
We get rid of try-finally w/ an empty finally (convert to normal code…).
We optimize branches over branches:
gotoif A, lab1
goto lab2:
lab1:
turns into: gotoif !A, lab2
lab1:
We optimize branches to ret, branches to next instruction, and branches to branches.

65
Q

Is there a way of specifying which block or loop to break out of when working with nested loops?

A
class BreakExample
{
public static void Main(String[] args)
{
for(int i=0; i);
}
}
66
Q

What is the difference between const and static read-only?

A
The difference is that static read-only can be modified by the containing class, but const can never be modified and must be initialized to a compile time constant. To expand on the static read-only case a bit, the containing class can only modify it: -- in the variable declaration (through a variable initializer). 
-- in the static constructor (instance constructors if it's not static).
67
Q

What is the difference between System.String and System.StringBuilder classes?

A

System.String is immutable; System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

68
Q

What is the top .NET class that everything is derived from?

A

System.Object.

69
Q

Can you allow class to be inherited, but prevent the method from being over-ridden?

A

Yes, just leave the class public and make the method sealed

70
Q

Are private class-level variables inherited?

A

Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.

71
Q

Can you inherit multiple interfaces?

A

Yes. .NET does support multiple interfaces.

72
Q

Why do I get a security exception when I try to run my C# app?

A

Some security exceptions are thrown if you are working on a network share. There are some parts of the frameworks that will not run if being run off a share (roaming profile, mapped drives, etc.). To see if this is what’s happening, just move the executable over to your local drive and see if it runs without the exceptions. One of the common exceptions thrown under these conditions is
System.Security.SecurityException.
To get around this, you can change your security policy for the intranet zone, code group 1.2, (the zone that running off shared folders falls into) by using the caspol.exe tool.

73
Q

Is there any sample C# code for simple threading?

A
Some sample code follows: using System;
using System.Threading;
class ThreadTest
{
public void runme()
{
Console.WriteLine("Runme Called");
}
public static void Main(String[] args)
{
ThreadTest b = new ThreadTest();
Thread t = new Thread(new ThreadStart(b.runme));
t.Start();
}
}
74
Q

How do you inherit from a class in C#?

A

Place a colon and then the name of the base class. Notice that it is double colon in C++.

75
Q

Does C# support multiple inheritance?

A

No, use interfaces instead.

76
Q

What is an interface class?

A

It is available to derived classes and classes within the same Assembly (and naturally from the base class it is declared in).

Interfaces are contracts that a class implements in its own way. This means an interface will contain function prototypes and a class that marries this interface will have to take the responsibility of defining the functions whose prototypes are declared by the marrying interface.

An interface is nothing more than an agreement of how two pieces of code will interact. One piece of code implements the interface and another uses the interface. The interface acts as a decoupling layer that enables the replacement of the object implementing the interface.

class Demo : abc
{
  public static void Main()
  {
   System.Console.WriteLine("Hello  Interfaces");
    Demo refDemo = new Demo();
    refDemo.xyz();
    Sample refSample = new Sample();
    refSample.xyz();  
  }
  public void xyz()
  {
     System.Console.WriteLine("In xyz");
  }  
}
interface abc
{
  void xyz();
}
class Sample : abc
{
  public void xyz()
  {
     System.Console.WriteLine("In Sample :: xyz");
  }  
}

In Demo :: xyz
In Sample :: xyz

77
Q

How can I get around scope problems in a try/catch?

A
Connection conn = null;
try
{
conn = new Connection();
conn.Open();
}
finally
{
if (conn != null) conn.Close();
}
By setting it to null before the try block, you avoid getting the CS0165 error (Use of possibly unassigned local variable 'conn').
77
Q

Why do I get an error (CS1006) when trying to declare a method without specifying a return type?

A

If you leave off the return type on a method declaration, the compiler thinks you are trying to declare a constructor. So if you are trying to declare a method that returns nothing, use void. The following is an example: // This results in a CS1006 error public static staticMethod (mainStatic obj) // This will work as wanted public static void staticMethod (mainStatic obj)

78
Q

How do I convert a string to an int in C#?

A
Here's an example: using System;
class StringToInt
{
public static void Main()
{
String s = "105";
int x = Convert.ToInt32(s);
Console.WriteLine(x);
}
}
79
Q

How do you directly call a native function exported from a DLL?

A
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.
80
Q

What is the difference between a struct and a class in C#?

A
From language spec:
The list of similarities between classes and structs is as follows. Longstructs can implement interfaces and can have the same kinds of members as classes. Structs differ from classes in several important ways; however, structs are value types rather than reference types, and inheritance is not supported for structs. Struct values are stored on the stack or in-line. Careful programmers can sometimes enhance performance through judicious use of structs. For example, the use of a struct rather than a class for a Point can make a large difference in the number of memory allocations performed at runtime. The program below creates and initializes an array of 100 points. With Point implemented as a class, 101 separate objects are instantiated-one for the array and one each for the 100 elements.
81
Q

How can you overload a method?

A

Different parameter data types, different number of parameters, different order of parameters.

82
Q

How can I get the ASCII code for a character in C#?

A

Casting the char to an int will give you the ASCII value: char c = ‘f’; System.Console.WriteLine((int)c); or for a character in a string: System.Console.WriteLine((int)s[3]); The base class libraries also offer ways to do this with the Convert class or Encoding classes if you need a particular encoding.

83
Q

How do I create a Delegate/MulticastDelegate?

A

C# requires only a single parameter for delegates: the method address. Unlike other languages, where the programmer must specify an object reference and the method to invoke, C# can infer both pieces of information by just specifying the method’s name. For example, let’s use System.Threading.ThreadStart: Foo MyFoo = new Foo(); ThreadStart del = new ThreadStart(MyFoo.Baz); This means that delegates can invoke static class methods and instance methods with the exact same syntax!

84
Q

How can I access the registry from C# code?

A
class regTest
{
public static void Main(String[] args)
{
RegistryKey regKey;
Object value;
regKey = Registry.LocalMachine;
regKey =
regKey.OpenSubKey("HARDWAREDESCRIPTIONSystemCentralProcessor ");
value = regKey.GetValue("VendorIdentifier");
Console.WriteLine("The central processor of this machine is: {0}.", value);
}
}
85
Q

What is the difference between an interface and abstract class?

A

In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

86
Q

What is an abstract class?

A
A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, it is a blueprint for a class without any implementation. 
_break
87
Q

Who is a protected class-level variable available to?

A

It is available to any sub-class (a class inheriting this class).

88
Q

What is the syntax to inherit from a class in C#?

A
Place a colon and then the name of the base class.
Example: class MyNewClass : MyBaseClass
89
Q

Can you prevent your class from being inherited by another class?

A

Yes. The keyword “sealed” will prevent the class from being inherited.

90
Q

What’s an abstract class?

A

A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.

91
Q

When do you absolutely have to declare a class as abstract?

A
  1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
  2. When at least one of the methods in the class is abstract.
92
Q

What’s the difference between an interface and abstract class?

A

In an interface class, all methods are abstract - there is no implementation. In an abstract class some methods can be concrete. In an interface class, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers.

93
Q

What is the difference between a Struct and a Class?

A

Struts are value-type variables and are thus saved on the stack, additional overhead but faster retrieval. Another difference is that struts cannot inherit.

94
Q

What’s the implicit name of the parameter that gets passed into the set method/property of a class?

A

Value. The data type of the value parameter is defined by whatever data type the property is declared as.

95
Q

What does the keyword “virtual” declare for a method or property?

A

The method or property can be overridden.

96
Q

How is method overriding different from method overloading?

A

When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class.

97
Q

Can you declare an override method to be static if the original method is not static?

A

No. The signature of the virtual method must remain the same. (Note: Only the keyword virtual is changed to keyword override)

98
Q

What are the different ways a method can be overloaded?

A

Different parameter data types, different number of parameters, different order of parameters.

99
Q

What is the smallest unit of execution in .NET?

A

an Assembly.

100
Q

How do you convert a value-type to a reference-type?

A

Use Boxing.

101
Q

What happens in memory when you Box and Unbox a value-type?

A

Boxing converts a value-type to a reference-type, thus storing the object on the heap. Unboxing converts a reference-type to a value-type, thus storing the value on the stack.Difference between directcast and ctype.

102
Q

What are the two kinds of properties.

A

Two types of properties in .Net: Get and Set

103
Q

Difference between value and reference type. what are value types and reference types?

A

Value type - bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short, strut, uint, ulong, ushort
Value types are stored in the Stack
Reference type - class, delegate, interface, object, string
Reference types are stored in the Heap

104
Q

Explain constructor.

A

Constructor is a method in the class which has the same name as the class (in VB.Net its New()). It initializes the member attributes whenever an instance of the class is created.

105
Q

How can you clean up objects holding resources from within the code?

A

Call the dispose method from code for clean up of objects

106
Q

Which controls do not have events?

A

Timer control.

107
Q

What is the maximum size of the textbox?

A

65536

108
Q

Which property of the textbox cannot be changed at runtime?

A

Locked Property.

109
Q

Which control cannot be placed in MDI?

A

The controls that do not have events.

110
Q

What is the difference between proc. sent BY VAL and BY SUB?

A

BY VAL: changes will not be reflected back to the variable.

By REF: changes will be reflected back to that variable.( same as & symbol in c, c++)

111
Q

Who is a protected class-level variable available to?

A

It is available to any sub-class (a class inheriting this class).

112
Q

Are private class-level variables inherited?

A

Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.

113
Q

Describe the accessibility modifier “protected internal”.

A

The data value may not be changed. Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.

114
Q

What’s the difference between System.String and System.Text.StringBuilder classes?

A

System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

115
Q

What’s the advantage of using System.Text.StringBuilder over System.String?

A

StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.