C# The Basics - Lessons

 

The Visual Studio 2022 IDE

Welcome to the Visual Studio 2022 Integrated Development Environment (IDE). Learning C# gets you right into creating programs with a graphical user interface (GUI) look to them.  Comes right with the package. What I like about C# over the other two is that you can start out with the GUI interface as you learn programming. Programming with a GUI right from the start is a lot more rewarding for the new programmer.  You are building programs that look like the ones we use today.  That alone keeps the motivation going.

The Text Box and String Variables

Up to now we have been doing straight line programming.  One line of code follows another.  And then it’s done.  That pretty much limits what we can do.  So, it only makes sense that we expand on that. We’ll continue to use variables, controls, and the GUI.  And we’ll add to our knowledge in this area as we continue our journey.  But now we get a chance to expand what our programs can do.

The first thing we’ll look at is the Decision Structure. The tools in the decision structure allow our programs to branch off in other directions. 

How String Variables are Stored

When we work with strings it is important to understand what they are and how the computer sees them. In order to do that we have to understand how the computer communicates with us. Since we can’t talk to the computer in English, or any other language for that matter, we need another form of communications. ASCII stands for American Standard Code for Information Interchange. Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as 'a' or '@' or an action of some sort.

String Concatenation

String Concatenation is simply gluing one string to another to form a larger string or a new string altogether. 

Variable Scope

When you create a variable in memory, depending on where it is initialized, the variable may be invisible to certain routines.  If it’s invisible, then a routine without permission can’t use it. Where we declare a variable determines how it can be seen. That’s Scope.

How Numeric Variables are Stored

Numeric variables are reserved for data used in calculations.  Plain and simple. When those numeric variables are to be displayed on a screen or a printer they must be converted to strings. Numeric variables come in a variety of sizes and flavors.  This makes it a little harder for the new programmer at first but in the long run it makes sense.

Math

In C# and in any programming language we can do Addition, Subtraction, Multiplication and Division.  There is one more operation we can do with may seem new.  It’s called Modulus.  And that’s simply division where only the remainder is given.

Simple Exception Handling

The Try-Catch statement can prevent our programs from blowing up when the user enters something they weren’t supposed to. And users tend to do that.

The Random Number Generator

Often used in card games and dice games the random number generator is an object that stores a random number, integer or double, into a variable you declare

Odds and Ends

Tab Order, Access Keys, Color and Graphics are all enhancements to our programs that make life easier for the user.