C#. last minute prep Flashcards

(9 cards)

1
Q

How to convert character/string to upper/lowercase?

A

string one = “Hi”;
string oneUpper = one.ToUpper();

char two= “h”;
char twoUpper = Char.ToUpper(two);

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

What does .ToUpper() do for numbers?

A

It just returns the number on its own, does not produce an errror.

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

How to check if a character is upper/lowercase, or a digit?

A

char two= “H”;
Char.IsUpper(two); //true

int three = 9;
Char.IsDigit(three) //true

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

Math operators and rules for truncating, power, and rounding (to a select D.P.) on int num;

A

double num = 3.1415;

double power = Math.Pow(2,4);
double truncate = Math.Truncate(num);
double rounded = Math.Round(num, 2);

must always work in doubles.

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

String handling, how to do:
- Index of a character (and if it isn’t present)
- Last index of a character (and if it isn’t present)
- Make a substring

A

string EmailPosition = “faisal@lgs.slough.sch.uk”;
int PosOfAtSign = EmailPosition.IndexOf(“@”);

int PosOfL = EmailPosition.LastIndexOf(“l”);
Console.WriteLine(PosOfL);

string hi= “Berub”;
string hi1 = hi.Substring(0, hi.Length);
//(start index, num of characters)

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

Appending strings

A

string text = “”;
text += “A”;
text += “3”;

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

How to convert from CHAR to ASCII code, and ASCII code to CHAR?

A

ASCII code TO INT:
char ascii = ‘A’;
int number = (int)ascii;

ASCII code to character:
int code = 66;
char ascii = (char)code ;

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

Convert from F/D to INT, and STRING to F/D

A

int number = (int)double ; //truncates

double = double.Parse(string);

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

List functions:
- Convert from string to list of characters
- Insert value at specific index
- Index of a value
- Remove a value
- Remove the item at a specific index
- Sort into alphabetic order A -> Z
- Reserve order of list

A

List<char> letters = string.ToList();</char>

letters.Insert(3, ‘A’)

letters.IndexOf(‘A’) //first instance, or -1

letters.Remove(‘A’) //remove first instance

letters.RemoveAt(2)

letters.Clear() //empty list

letters.Sort() //alphabetic order

letters.Reverse() //reverses order

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