Coding tips to learn Flashcards

1
Q

Modulus

A

Find remainder - %

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

Truncation of a string

A

string Substring(int startIndex)
string Substring(int startIndex, int length)

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

Random number generation

A

Random rnd = new Random();
int number = rnd.Next(1,13) // between 1 and 12

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

What is a local variable?

A

can only be accessed from the subroutine within which it is declared

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

what is a global variable?

A

can be accessed from any part of the program

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

How do you declare an array?

A

string[] cars;

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

How do you add values to your array?

A

cars = new string[] {“Volvo”, “BMW”, “Ford”}

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

How to change values in an array?

A

cars[0] = “Opel”;

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

How to convert a string to an array?

A

char[] chars = input.ToCharArray();

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

How to convert array to string?

A

string output = new string(chars)

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

How do you make a Dictionary?

A

Dictionary<TKey, TValue> dictionaryName = new Dictionary<TKey, TValue>();

(where Tkey and TValue are data types. )

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

How do you loop through a Dictionary?

A

when looping through a dictionary you are looping through the pairs in the dictionary….

foreach (var pair in nameOfDictionary)
{
}

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

Getting the Key or Value of a pair in a Dictionary:

A

in forloop ….
pair.Key
pair.Value

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

How do you change a value in a Dictionary?

A

nameOfDictionary [TKey] = TValue

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

How to check a string contains a certain string/char:

A

“STRING”.Contains(c.ToString())
//for char

OR

“STRING”.Contains(str)
//for substring

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