H1-3 Flashcards
Convert to other type
System.Convert.To…(value)
[struct] do you always get default values?
No, only when using new, calls the constructor
[struct] how many parameters go in the constructor?
All fields otherwise compile exception.
[Optional] what is a restriction with optional parameters?
(Par1 = 1, Par2 = 2), can’t do (Par2 only) because then you need to do Par1 also.
How can you call parameters by name
(parameter1 : value, parameter2 : value)
give an example of a for loop with empty definitions
for(;;)
{
if(xxxx) break;
}
what is an indexed property?
public class IPAddress { private int[] ip; public int this[int index] { get { return ip[index]; } set { if (value == 0 || value == 1) ip[index] = value; else throw new Exception("Invalid value"); } } }
How do you use an indexed property
IPAddress myIP = new IPAddress(); // initialize the IP address to all zeros for (int i = 0; i < 32; i++) { myIP[i] = 0; }
give an example of a generic queue class
// example of a generic style Queue public class GenericQueue{T} { public void Enqueue(T obj); public T DeQueue(); }
Give an example of a generic methode.
// example of generic method with type parameters public void Swap{T}(T valueOne, T valueTwo) { T temp = valueOne; valueOne = valueTwo; valueTwo = temp; }
give an example of an enumeration in code
enum Months {Jan, Feb, March, …}
give an example of an enumuration that is not an int
enum Months : byte {Jan, Feb, …}
give an example of an enumeration that starts with 4 and not the default 0.
enum Months {Jan = 1, Feb, … }
Give an example of an extention methode
public static class MyExtendedMethods { public static int square(this int num) { int result = 0; result = num * num; return result; } }
How many indexed properties can a class have?
One.