Skip to content

Instantly share code, notes, and snippets.

@DanielFerguson
Last active February 14, 2016 08:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DanielFerguson/43d842de503be27bd756 to your computer and use it in GitHub Desktop.
Save DanielFerguson/43d842de503be27bd756 to your computer and use it in GitHub Desktop.
C# Code Notes (Volume 1)
// Init a data type
int intName;
string stringName;
double doubleName;
float floatName;
// Creates a CONST variable - cannot be modified, or reassigned
const int intName;
// Show a MessageBox
MessageBox.Show("Main Message", "Caption", MessageBoxButton.OKCancel, MessageBox.Error);
// IF Statement
if (true)
{
// IF STATEMENT IS (=) TRUE
} else {
// IF STATEMENT NOT (!=) TRUE
}
// Take a STRING input from XAML Display
string stringInput = stringInputBox.Text;
// Take an INT input from XAML Display using PARSE
int intInput = int.Parse(stringInput.Text);
// Take an INT input from XAML Display using TRYPARSE
int intInput
int.TryParse(numberInput.Text, out intInput);
// CASE / SWITCH
// Used instead of IF
int yearLevel = 11;
switch (yearLevel)
{
case 12: locationBox.Text = "Please go to the Centennial Wing, North end";
break;
case 11: locationBox.Text = "Please go to the Centennial Wing, South end";
break;
}
// FOR LOOP
for (int count = (startnumber); count < (maxnumber); count+(increasebynumber))
{
counterDisplay.Text = i
}
// DO LOOP (Test condition at END)
int count = start;
do
{
countDisplay.Text += "\r\n" + 1;
count+=1;
} while (count<10);
// WHILE LOOP (Test condition at START)
int count = start;
while (count<10)
{
countDisplay.Text += "\r\n" + count;
count+=1;
}
// Data Types
string // STRING of characters, a sentence , Size (bits) 16 per Char
int // a WHOLE number , Size (bits) 32
double // an EXACT number , Size (bits) 64
bool // TRUE or FALSE, 1 or 0, ON or OFF , Size (bits) 8
float // FLOATING-POINT numbers , Size (bits) 32
long // WHOLE number (bigger range) , Size (bits) 64
char // a CHARACTER , Size (bits) 16
decimal // MONETARY values , Size (bits) 128
// PRINT to a TextBox
outputTextBox.Text = "Outputed Text";
// PRINT custom string to TextBox
value = 13452928
outputTextBox.Text = value.ToString("$#,##0;$(#,##0)");
// PRINT to a TextBox, and to a New Line every time
countedOutput.Text += "\r\n" + "Outputted text";
// SCOPES - PRIVATE and PUBLIC
// PRIVATE can only be called upon in the surrounding method,
// whereas PUBLIC can be called upon in every method
// Defining Methods -
//NORMAL - End of code
void add2numbers(int int1, int int2)
{
int sum = int1 + int2;
MessageBox.Show("The sum of " + int1.ToString() + " + " + int2.ToString() + " = " + sum.ToString());
return;
}
//RETURN A VALUE - Use if not end of code
private int subtract2numbers(int int1, int int2)
{
int diff;
diff = int1 - int2;
return diff;
}
// CLOSE a program
Close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment