Coding tips to learn Flashcards
Modulus
Find remainder - %
Truncation of a string
string Substring(int startIndex)
string Substring(int startIndex, int length)
Random number generation
Random rnd = new Random();
int number = rnd.Next(1,13) // between 1 and 12
What is a local variable?
can only be accessed from the subroutine within which it is declared
what is a global variable?
can be accessed from any part of the program
How do you declare an array?
string[] cars;
How do you add values to your array?
cars = new string[] {“Volvo”, “BMW”, “Ford”}
How to change values in an array?
cars[0] = “Opel”;
How to convert a string to an array?
char[] chars = input.ToCharArray();
How to convert array to string?
string output = new string(chars)
How do you make a Dictionary?
Dictionary<TKey, TValue> dictionaryName = new Dictionary<TKey, TValue>();
(where Tkey and TValue are data types. )
How do you loop through a Dictionary?
when looping through a dictionary you are looping through the pairs in the dictionary….
foreach (var pair in nameOfDictionary)
{
}
Getting the Key or Value of a pair in a Dictionary:
in forloop ….
pair.Key
pair.Value
How do you change a value in a Dictionary?
nameOfDictionary [TKey] = TValue
How to check a string contains a certain string/char:
“STRING”.Contains(c.ToString())
//for char
OR
“STRING”.Contains(str)
//for substring