Category Archive for: C# Basics

Enumerations

An enumeration is a user-defined integer type. When you declare an enumeration, you specify a set of acceptable values that instances of that enumeration can contain. Not only that, but you can give the values user-friendly names. If, somewhere in your code, you attempt to assign a value that is not in the acceptable set of values to…

Read More →

Jump Statements

C# provides a number of statements that allow you to jump immediately to another line in the program. The first of these is, of course, the notorious goto statement. The goto Statement The goto statement allows you to jump directly to another specified line in the program, indicated by a label (this is just an identifier followed…

Read More →

Loops

C# provides four different loops (for, while, do-while, and foreach) that allow you to execute a block of code repeatedly until a certain condition is met. The for, while, and. do …while loops are essentially identical to those encountered in C++. The for Loop C# for loops provide a mechanism for iterating through a loop where you…

Read More →

Flow Control

This section looks at the real nuts and bolts of the language: the statements that allow you to control the of your program rather than executing every line of code in the order it appears in the program. Conditional Statements Conditional statements allow you to branch your code depending on whether certain conditions are met or on…

Read More →

Predefined Reference Types

C# supports two predefined reference types, object and string, described in the following table. The object Type Many programming languages and class hierarchies provide a root type, from which all other objects in the hierarchy are derived. C#  and .NET are no exception. In C#, the object type is the ultimate parent type from which an other…

Read More →

Predefined Data Types

Now that you have seen how to declare variables and constants, let’s take a closer look at the data types available in C#. As you will see, C# is much stricter about the types available and -their definitions than some other languages are. Value Types and Reference Types Before examining the data types in C#, it is important…

Read More →

Variables

You declare variables in C# using the following syntax: data type identifier; For example: int i; This statement declares an int named i.The compiler won’t actually let you use this variable in an expression until you have initialized it with a value. Once it has been declared, you can assign a value to the variable using…

Read More →

A Closer Look

First, a few general comments about C# syntax. In C#, as in other C-style languages, most statements end in a semicolon (; ) and can continue over multiple lines without needing a continuation character (such as the underscore in Visual Basic). Statements can be joined into blocks using curly braces ({)). Singleline comments begin with two forward slash…

Read More →

Your First C# Program

Let’s start by compiling and running the simplest possible C# program – a simple class consisting of a console application that writes a message to the screen. The most common technique for writing C# programs is to use Visual Studio 2008 to generate a basic project and add your own code to it. However, because the aim of…

Read More →

C# Basics

Now that you understand more about what C# can do, you will want to learn how to use it. This chapter gives’ you a good start in that direction by providing you with a basic knowledge of the fundamentals of C# programming, which is built on in subsequent chapters, The main topics covered are: Declaring variables Initialization and…

Read More →

Back to Top