C# and OOP Flashcards
Printing a line
Console.WriteLine(iValue);
Converting number to string
string strValue = floatValue.ToString();
Casting float to int
int iValue = (int)fValue;
(rounds down)
Converting string to number
string strValue = “13.8”;
float fValue = float.Parse(strValue);
Getting a substring of a string
string.Substring(a, b) gives you the b characters which come after character a
“vge1974”.Substring(2, 4) = “e197”
Conditional statement
if (condition)
{
code
}
else
{
more code
}
Comparison operators
==, !=, <, >, <=, >=
Logical operators
&&, ||, !
“true”, “false”
Expressing x^y
Math.Pow(x, y)
While loop
while (condition)
{
code
}
(can control flow using “break” and “continue”)
Do while loop
do
{
code
}
while (condition)
For loop
for (setup; condition; increment)
{
code
}
Foreach loop
foreach (<type> currentItem in listOfItems)
{
code
}</type>
What is OOP?
A programming framework that facilitates the reuse and extensibility of code. Bits of source code with relevant purposes are grouped together as classes, managed as a hierarchy with inheritance. Objects are instances of a class, which is like a blueprint.
Advantages of OOP
With OOP, source code becomes easier to maintain and follow
Code can be reused through inheritance, improving efficiency and productivity
Security through encapsulation