Posts

Showing posts from May, 2022

10. C# - OOP

CLASSES: // like functions class className { things } FIELDS: // variables that goes inside classes private string name; private const int hourlyRate; private // only class can use the fields public // allows other classes to access the field/property protected internal

1. Git - Version Control with GitHub and Git

 Controlling file versions and projects. Committing Process: Modifying (modify files) -> Staging (picking which modified file to commit) -> Committing - push to make changes from local to server - pull to make changes from server to local How to start: In terminal: - git init // initializes a git folder - git status // shows the status of project - git add <filename> // adds a file to the staging process     - git add . // stages all modified files - git commit -m "STRING MESSAGE" - git checkout -- <filename> // retrieve file from git repo - git remote add origin <githubRepoLink> // link origin branch to the github repo     - need setup before using "git push" shortcut     - git push --set-upstream origin master - git push origin master // pushes the origin(localname) to the master branch in github Pulling: - git pull origin master // pulls the master branch Branches: - master branch // the main branch that contains original code and their ev

9. C# - Try/Catch

 try {     try something } catch (Exception e) {     Console.WriteLine(e.Message);     // or do something to mark the error/exception (many type of exceptions available)     //  https://msdn.microsoft.com/en-us/library/system.systemexception.aspx } finally {     Console.WriteLine("Test"); }

8. C# - BREAK/CONTINUE JUMPS

 Breaks: break; // breaks loops Continue: continue; // skips any code after/below it if conditions are met. Example: for (int i = 0; i<5; i++)  {  Console.WriteLine(“i = {0}”, i); if (i == 2)  continue;  Console.WriteLine(“I will not be printed if i=2.\n”);  }

7. C# - Switch Case & LOOPS

 SWITCH: switch (variable) { case (condition):      do something     break; case (condition):     do something     break; default:     break; } FOR LOOPS (LIKE GOLANG) for (conditions) { do something } FOREACH LOOP (LIKE GOLANG, ARRAY LOOP WITH INDEX AND ELEMENT) foreach (char i in variableArray)     do something with i WHILE LOOPS while (condition) { do something DO WHILE // does the check after doing it atleast once do {     do something } while (condition); }

6. C# - IF/THEN/ELSE

 SYNTAX: if (condition) { do something } else if (condition) { do something } else { do something } Inline IF (Short IF) (condition) ? valueIfTRUE : valueIfFALSE; // returns the true or false values depending on the condition

5. C# - Escape Symbols

Escape Character: use the "\" symbol to escape symbols in strings \\  // this escapes the backslash itself \t // this creates a tab \n // this creates a newline

4. C# - List

 Lists: // are like array but flexible. arrays are fixed lengths while list can be flexible with adding and removing. List Declaring: List<dataType> variableName = new List<dataType>(); // initialize empty list List<int> variableName = new List<int>{5,1,3,5,3}; // initializes a filled list List Indexing: // Same as array listName[0]; List Methods: Add() Method: listVariable.Add(newValueToAdd); // adds a new value to the list at the end of the list Count Method: listVariable.Count; // returns the length of the list Insert() Method: listVariable.Insert(index, value); // inserts a value at a specified location, moving other values up/down to make space Remove() Method: listVariable.Remove(value); // removes the FIRST appearance of a value from the list RemoveAt() Method: listVariable.RemoveAt(index); // removes the value at the specified index Contains() Method: listVariable.Contains(valueToSearch); // returns true or false if found Clear() Method: listVariable.Cle

3. C# - Strings

  String Length Method: stringVariable.Length; // returns length of string String Substring Method: stringVariable.Substring(minRange, maxRange); // returns the given substring between those two index ranges String Equals Method: stringVariable.Equals(stringVariableToCompare); // returns true or false if they equal String Split Method: // this method splits a string and places the results into an string array string [] separators = {"," , ":"}; // creates an array that list what the separators are contained in quotations and separated by commas. string [] names = {"PETER, JOHN; ANDY, , DAVID"}; string [] results = names.Split(separators, StringSplitOptions.None); // this creates an array to hold the results. parameters are the separators and the split option with method none. // change the method from None to RemoveEmptyEntries will skip empty results. Convert Method: int variable = Convert.ToInt32(variableBefore); decimal variable = Convert.ToDecimal(vari

2. C# - Arrays

 Declaring Arrays: int[] myarray = new int[5]; // this declares a new empty array with 5 spots // block brackets in front of a data type indicates its an array consisting of those data types int[] myarray = int{1, 2, 3, 4}; // declares an array with preset values Indexing Arrays: Console.WriteLine(myarray[0]); // prints "1" Length Method: myarray.Length // tells us length of array Array Copy Method: Array.Copy(sourceArray, destinationArray, numberofvaluestocopy); // copies a set of values from one array and replaces those number of elements in the new array. Array Sort Method: Array.Sort(numberArray); // sorts it into ascending order Array IndexOf Method: Array.IndexOf(arrayname, valuetofind); // returns the index if it finds the value inside the array given

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 nu