Object Types
int - Integer |
double - Floating binary-point number (exact) |
float - Floating binary-point number (estimate) |
decimal - Decimal number (exact) |
string - Char array |
char - Character |
bool - True/false boolean |
var - Dynamic variable |
Using Statements
Using statements are declarations of which code libraries are being utilized within this file / class. Additionally, if declared similarly to a variable, a shortened keyword can be used in place of a full-length declaration further within the code.
For example:
using System;
using System.Diagnostics;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
|
Using the Console
var input = Console.ReadLine();
|
Gets the last line input to the console and saves it to variable 'input' |
|
Writes the text-representation of the variable (any) and does not move to the next line |
Console.WriteLine({{x}});
|
Writes the text-representation of the variable (any) and moves to the next line |
Use a variable name in place of {{x}}
Comments
// |
Single-line comment |
/* |
Begin multi-line comment |
*/ |
End multi-line comment |
|
|
Declaring a Variable
Declaring a variable is as easy as knowing the type of variable needed, a name for the variable, and the default (a.k.a. initial) value for said variable.
{Variable Type} {Variable Name} = {Default / Initial Value};
Say we need to create an integer named "itemCount":
int itemCount = 0;
Now what about a true/false statement named "validated":
bool validated = false;
A variable based off a class named "Car" with a variable named "newCar":
Car newCar = new Car();
|
Declaring a Method
Declaring a method is nearly as simple as declaring a variable, you must know the publicity of the method, the return type (if one is needed), the name of the method, and any arguments (data) that is needed by the method. Remember, you create the name of the method.
{Publicity} {Return Type} {Method Name} ({Arguments})
Lets say we need a public method that returns an integer named "Add" that takes two integers as arguments:
public int Add (int number1, int number2)
We can also declare a method with an optional parameter by declaring an argument with a default value:
public int Add (int number1, int number2, int number3 = 0)
Alternatively, we can create methods that don't return anything:
public void DoSomething ()
|
|
|
Publicity / Access Modifiers
public |
Accessible from any class within any assembly or namespace |
internal |
Accessible from any class within only this assembly |
protected |
Accessible only by this class and any class derived or inherited by this class |
private |
Accessible only by this class |
Access modifiers can be used on Methods, Classes, and even Variables, to allow for granular access to only the necessary aspects of your code.
Access Modifiers
Utilizing Git (Building a Portfolio) WIP
Firstly, ensure you have a GitHub or other Git application account. Most beginning / solo developers prefer GitHub for its ease-of-use and issue tracking capabilities.
Once an account is created, create a project (a.k.a. repository) and name it appropriately in the application, include as much detail, and a description, as possible.
From the newly created project's dashboard, look for a button to clone the repository to your machine. A few options may be presented, and if using both Visual Studio and GitHub, the 'Clone to Visual Studio' magnet button is a quick and efficient way of cloning the repository locally. |
Logical Operators
== |
Equal to |
!= |
Not equal to |
&& |
And (i.e. A == 1 && B == 2) |
|| |
Or (i.e. A == 1 || B == 2) |
>= |
Greater than or equal to |
<= |
Less than or equal to |
> |
Greater than |
< |
Less than |
|