We will start these first several C# post’s by following along with the Microsoft Learn Certification for C#, hosted by FreeCodeCamp.com. Though, I will add my own information from other sources throughout.

  • C# is a case-sensitive language.
    • This means that the C# compiler is consider’s “console.WriteLine();” to be different from “Console.WriteLine();”.
  • Comments in C# are created by adding two forward slashes “//“.
    • The following is an example of commented code, which the IDE will not compile:
// Console.WriteLine("Hello World!"); 
  • Console.WriteLine(); prints the output on the existing line and appends a new line after it.
    • Console.Write(); prints the output on the current line.
Console.WriteLine("Congratulations!"); 
Console.Write("You wrote your first lines of code."); 
Console.Write(" I am so proud of you!!"); 

Whereas . . .

Console.WriteLine("Congratulations!");
Console.WriteLine("You wrote your first lines of code.");
Console.Write("I am so proud of you!"); 
  • In the above code, “Console.WriteLine”, the “Console” portion is considered a class.
    • Methods live inside of Classes. To utilize the method, you must know which Class the method resides within.
      • The method in “Console.WriteLine” is “WriteLine”, and it comes after the “.”
        • The class “Console” comes before the “.
    • This separating “.” is considered a member access operator.
      • This member access operator is how you “navigate” from the class to the methods inside.
  • Methods in C#, has a set of parentheses after it.
    • “Console.Write();”
      • Some method’s need input parameters, while other’s do not.
        • The input parameters go inside the parenthesis.
    • The parenthesis themselves are considered method invocation operators.
    • The semicolon is the end of statement operator. The semicolon tells the compiler that you’ve finished entering the command.
      • A statement is a complete instruction in C#.

Remember:

  • (1) A statement is a complete instruction in C#.
  • (2) C# is a case-sensitive language, so capitalization matters.
  • (3) Classes come before methods, methods come after the period, which is a member access operator.

Challenge

Write code that would produce this output:

Console.WriteLine("This is the first line.");
Console.WriteLine("This is the second line.");
Console.Write("Jesus loves us."); 

OR

Console.WriteLine("This is the first line.");
Console.Write("This is ");
Console.Write("the second ");
Console.WriteLine("line.");
Console.Write("Jesus loves us.");  

***In reality, there are more ways to achieve the stated Output. These are just two of the possible ways. Each way likely has it's own pro's & con's. 


Comments

One response to “C# : Post #1”

  1. […] C#: Object-oriented programming […]

Leave a Reply

Your email address will not be published. Required fields are marked *