C++/C# Programming


Home

Here's some useful links: 

https://csharpplayersguide.com
 https://csharpplayersguide.com/solutions
 https://charpplayersguide.com/errata
http://csharpplayersguide.com/articles
 https://csharpplayersguide.com/discord
 ttps://csharpplayersguide.com/contact

Notes for C#

ConsoleApp1.exe
Practice C# program

Here's the code for a short program using variables:

 

Console.WriteLine("Hello, World!");
Console.Beep(440, 1000);
Console.WriteLine("What is your name?");
string name;
name = Console.ReadLine();
Console.WriteLine("Hi" + name + ", I guess you're here to find out the size of the triangles you are selling. What is the length of the triangle?");
string input2 = Console.ReadLine();
int lenTR = Convert.ToInt32(input2);
Console.WriteLine("Now tell me the height of your triangle");
string input3 = Console.ReadLine();
int hiTR = Convert.ToInt32(input3);
var totalTR = (lenTR * hiTR) / 2;
Console.WriteLine("The area of the triangle is " + totalTR);
Console.Beep(440, 1000);

While this works, is there a cleaner way to handle the int/string conflict?

 

Console.WriteLine("So, you want to know how many apples each of you get. You all get the same number, and Edward there in the corner gets the remainer of what can not be divided evenly.");
Console.Beep(440, 1000);
Console.WriteLine("How many apples are we making available to the four of you?");
string totalApples = Console.ReadLine();
int numApples = Convert.ToInt32(totalApples);
int eachPerson = numApples / 4;
Console.WriteLine(eachPerson + " is the number of apples each person gets.");
Console.Beep(440, 1000);
int leftApple = numApples - (eachPerson * 4);
Console.WriteLine("Left over is " + leftApple + " apples");
Console.Beep(440, 1000);

a++ is the same as
a = a + 1;

a-- is the same as
a = a -1;

 

Math ---- MathF
Math.E Math.PI

Math.Pow(x, 2) same as x squared
Math.Sqrt Math.Pow
Math.Abs
Math.Sin(), Math.Cos(), Math.Min(), Math.Max()

\n equals new line
\t equals tab

Console.Write("What is your name, human? ");
string userName = Console.ReadLine();

Console.WriteLine("Press any key when you're ready to begin. ");
Console.ReadKey(true);

Console.WriteLine("Press any key to continue.");
Console.ReadKey(true);
Console.BackgroundColor = ConsoleColor.Yellow;
Console.WriteLine("Press any key to continue.");
Console.ReadKey(true);
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine("Press any key to continue.");
Console.ReadKey(true);
Console.Clear();
Console.Title = "Hello, World!";
Console.Beep();
Console.WriteLine("\""); // Allows quotemark when \ is added

Console.WriteLine("Press any key to continue.");
Console.ReadKey(true);
Console.BackgroundColor = ConsoleColor.Yellow;
Console.WriteLine("Press any key to continue.");
Console.ReadKey(true);
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine("Press any key to continue.");
Console.ReadKey(true);
Console.Clear();
Console.Title = "Hello, World!";
Console.Beep();
Console.WriteLine("\""); // Allows quotemark when \ is added
Console.WriteLine("Next enter one word and push Enter, and then a phrase, and push enter.");

string name1 = Console.ReadLine();
string name2 = Console.ReadLine();
Console.WriteLine($"#1: {name1,-20}");
Console.WriteLine($"#2: {name2,-20}");
Console.WriteLine($"{Math.PI:0.000}");

 

char letterGrade;

if (score == 200)

{
Console.WriteLine("A + Perfect score);
letterGrade = 'A';
}
else
{
Console.WriteLine("Try again.");
letterGrade = 'B';

}


If you're first starting out with C#, I'd recomment the six volume set,
Programming in Visual Studio C#, by Tim R. Wolf.
I'd also recommend C# Player's Guide, by RB Whitker.

Here's some additional sources for tackling C#:

Learning C3 by Developing Games with Unity 2021 - Ferrone
C#9 and .NET5 - Price
C# 7th edition - Murach
C# 4th edition - Stellman and Greene
C#10 and .NET6 - Price
C# 10.0- Mueller
C# 10 in a Nutshell - O'Reilly


A web-based compiler - https://ide.geeksforgeeks.org/

Notepad++ - very useful
(But have to turn on highlighting feature)

Code::Blocks - http://www.codeblocks.org/downloads/26

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Free Website Hit Counter
Free website hit counter