1. C# - Basics

 To create a C# app/program.

1. Create a project folder on computer.

2. Open CMD in folder. "dotnet new console"

3. In CMD, "code ." (there is a space and then a period) This opens the project in visual studio code.


Running/Building a C# script in terminal

dotnet run filename // run and debug the code

dotnet build filename // creates a EXE file to run


Namespace / librarie stuff

using NAMESPACENAME;

// namespace is a way to organize scopes of code. think of like folders.

// namespaces can be inserted into a code by using the "using NAMESPACENAME;"

// System, is a basic namespace


COMMENTING

// Single line comment

/* Block Comment */


BASIC HELLO AND WRITING

Console.WriteLine("HELLO"); // basically writes a print and newline

Console.Read(); // like waiting for input. reads next character

Console.ReadLine(); // reads a line of characters


Console.Write("HELLO"); // writes but without newline

// Concatenating with plus sign. Can concatenate numbers and strings.


string answer = Console.ReadLine(); // takes input and makes it a variable


Format Printing:

Console.Write("Hello {0}! Today is {1}", variableOne, variableTwo);

// like Printf in Golang, but uses index numbers as placeholders


Console.Write("{0:F3}", 123.1243132); // rounds and format number to 3 decimal places

// replace F3 with "C" will use Currency format for numbers, by add dollar sign. 


Data Types 

- string // a set of char, basically words/sentences. Uses double quotation marks.

        - concatenate strings by adding a plus sign between them

- int // int numbers

- byte // STRANGE, only integer numbers 0-255

- char // a C# version of golangs byte. basically single characters

        - initialize with single apostrophe

- double // similar to int64 but for floats // DECIMAL NUMBERS ARE DOUBLE DEFAULT

- float // float number // must add "f" suffix after number

- decimal // like float but more precision // must add "m" suffix after number

- bool // true/false


INITIALIZING VARIABLES

no value

variable_type variable_name;


one variable

variable_type variable_name = variable_value;


multiple variable (same type)

byte Age = 5, Weight = 10;


OPERATORS

+ add

- subtract

* multiply

/ divide

% modulus

+= // add self by value

-= // subtract self by value

*= // multiply self by value

++ // increment

-- // decrement


Type casting:

// converting one data type to another


double oldtype = 10.0;

int newtype = (int) oldtype;

// converting a double into an int. just add new data type within parenthesis when declaring a variable.

Comments

Popular posts from this blog

2. FreeCodeCamp - Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges

20. Data Analytics - Analyze Data to Answer Questions - Week 1

3. Algorithms - Selection Sort