- REPL stands for Read-Evaluate-Print-Loop. A REPL is a command line tool that allows users to enter lines of code and see the result in the terminal when executed.
- You may launch your REPL at any time with the command
$ dotnet script.
- Commands meant to run in the REPL are preceded with a
>in our curriculum. Commands meant to run in the standard command line are still preceded with
- Once open, you can exit the REPL with the
Ctrl + Ccommand.
- String: A sequence of characters between two quotation marks which is generally used for text content.
Concatenate: The act of making a new string out of multiple smaller strings, usually with a
+operator, like this:
"Hello" + " " + "World", which creates the string
Here's an example of concatenating multiple strings together in the C# REPL:
> "Programming" + " " + "is" + " " + "awesome!" "Programming is awesome!"
- In C#, all lines of code must end with a semi-colon (
;). There are a few exceptions we'll learn later, but don't worry about this for now.
- We can open the REPL with the
$ dotnet scriptcommand in the Terminal (for Mac) or Command Prompt (for Windows).
- Integers: A type of data representing whole numbers (numbers without decimals).
Operators: A special character (or characters) that indicates an action to be performed.
%are all operators for mathematic functions.
Basic arithmetic works just like you'd expect:
1 + 2 4 - 3 5 * 6 9 / 2 7 + 8 * 9 (7 + 8) * 9
9 % 2returns the remainder of 9 divided by 2.
%is called modulo.
Assignment Operator: The
=operator is used to set the initial value of a variable:
string exampleVariable = "hey, I'm a variable!";`
Strongly-Typed Language: A language in which data types must be declared. In the following example, we state that our variable has the
string anotherExampleVariable = "hey, I'm a variable too!";
- C# variables must declare the type of data they contain because C# is a strongly typed language.
- To create a C# variable we need three things:
- A descriptive name.
- A data type to declare what data the variable holds such as
- An initial value set with the assignment operator (
> string phrase = "Hello World";
stringis the data type our variable will be.
phraseis our descriptive name.
"Hello World"is the initial value.
- Arguments: Additional information provided to a method, passed in through the parentheses following the method name.
Substring: A small portion of a larger string. A bit like a single word in a larger sentence. For instance,
"hello"is a substring of the string
Pascal Case: Required naming convention for all C# methods in which all words are capitalized with no spaces. Examples include
Here are some examples of built-in methods you can call without arguments in the REPL:
> string phrase = "Programming is AWESOME"; > phrase "Programming is AWESOME" > phrase.ToUpper() "PROGRAMMING IS AWESOME" > phrase.ToLower() "programming is awesome"
Calling built-in methods with provided arguments:
> string phraseOne = "hello world"; > string phraseTwo = "hello"; > phraseOne.Contains(phraseTwo) true