C# Basics

Now that you understand a little more about what C# can do, you will want to learn how to use it.
This chapter on the basics of C# will give you a good start in that direction by providing you with a basic knowledge of the fundamentals of C# programming, which we will build on in subsequent chapters. The main topics we will be covering are:
❑ Declaring variables
❑ Initialization and scope of variables
❑ Predefined C# data types
❑ Dictating the flow of execution within a C# program using loops and conditional
statements
❑ Enumerations
❑ Namespaces
❑ The Main() method
❑ Basic command line C# compiler options
❑ Using System.Console to perform console I/O
❑ Using documentation features in C# and Visual Studio .NET
❑ C# identifiers and keywords
❑ Recommended guidelines and conventions for good programming in C#.

By the end of this chapter you will know enough C# to write simple programs, though without using inheritance or other object-oriented features, which are covered in the following chapters.

Before We Start

As we have already mentioned, C# is an object-oriented language. As we get you up to speed in the fundamentals
of the C# language, we will be assuming that you have a good grasp of the concepts behind
object-oriented (OO) programming. In other words, we will expect you to understand what we mean
by classes, objects, interfaces, and inheritance. If you have programmed in C++ or Java before, you should
have a pretty good grounding in object-oriented programming (OOP). However, if you do not have a
background in OOP, there are plenty of good sources of information on this subject. You can start with
Appendix A, which presents a detailed introduction to OOP concepts and is posted at www.wrox.com.
We also recommend Beginning Visual C#, the revised edition of Beginning C# for .NET v1.0 (ISBN
0-7645-4382-2) which teaches both object-oriented programming and C# from scratch.
If you are an experienced developer in Visual Basic 6, C++, or Java, you should note that we will make
many comparisons between C#, C++, Java, and Visual Basic 6 as we walk you through the basics of C#.
However, you might prefer to learn C# initially by reading a comparison between C# and your selected
language. If so, we have also made available separate documents for download on the Wrox Press Web
site (www.wrox.com) that give introductions to C# from the point of view of each of those languages.

Our First C# Program
Let’s start in the traditional way 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 Code
Type the following into a text editor (such as Notepad), and save it with a .cs extension (for example,
First.cs):
using System;
namespace Wrox.ProCSharp.Basics
{
class MyFirstCSharpClass
{
static void Main()
{
Console.WriteLine(“This isn’t at all like Java!”);
Console.ReadLine();
return;
}
}
}
The following chapters present a number of code samples. The most common technique for writing C#
programs is to use Visual Studio .NET to generate a basic project and add your own code to it. However,
since the aim of these early chapters is to teach the C# language, we are going to keep things simple and
avoid relying on Visual Studio .NET until Chapter 12. Instead, we will present the code as simple files
that you can type in using any text editor and compile from the command line.

Sursa
2007-07-14 20:04:00



Comenteaza





Ultimele 25 posturi adăugate

08:41:41Brexit: Petiția prin care britanicii cer ca Marea Britanie să rămână în UE a ajuns la 5 milioane de semnături —» Elena Robu
06:15:59Obiceiurile mele sănătoase de la început de zi —» Sunt MAMĂ!
05:05:42Țara din UE care a renunțat la bani: Folosește numerarul cel mai puţin de pe planetă —» Elena Robu
01:37:05Consiliul a decis sa scoata din oras antenele de telefonie mobila (RU) —» Curaj.TV | Media alternativă
23:34:36Le Sturmbannführer de la Brigade de choc prolétaire sur les murs du métro parisien —» Un PUNCT din .FR
22:09:08Ex Machina —» APort | "Pentru un român care știe citi, cel mai greu lucru e să nu scrie." I.L. Carag
20:52:44Şi-a serbat ziua de naştere la protestul #rezist —» Curaj.TV | Media alternativă
20:47:47Primăvară în noiembrie —» Frinturi din suflet de femeie
19:33:46Scandalul celor 200 de copii români care locuiesc în Spania fără documente a ajuns la Parlamentul European —» Elena Robu
19:23:03Șofer și pieton —» Primul meu blog
18:08:13Decizie definitivă pentru Laura Codruța Kovesi. Ce au decis judecătorii —» Elena Robu
17:59:19Tânăra care le învaţă pe femei cum să îşi găsească soţi bogaţi. Este vorba despre trei elemente cheie —» OligarhMD
17:58:59Cum a reuşit o tânără de 31 de ani să convingă mai mulţi bărbaţi să-i dea 85 de milioane de dolari pentru a-i susţine afacerea —» OligarhMD
16:55:03Noul Cod civil al Republicii Moldova —» Gheorghe Erizanu
15:38:53Electric Literature Moves to WordPress — Here’s How an Indie Publisher Thrives on the Open Web —» Blog Traduno.com
15:18:03Relația om-divinitate discutată la Universitatea de Stat ”D. Cantemir” —» Tineretul Ortodox
14:08:03Obiceiurile mele sănătoase de la început de zi —» Sunt MAMĂ!
13:39:22Peste 1 milion de utilizatori de Internet mobil 4G —» ITMOLDOVA
10:35:38Grigorciuc nu-i floare de cuc —» Gandrabur Corneliu
09:08:27Jandarmii îl reţin pe cel atacat la mitingul PSD —» Curaj.TV | Media alternativă
09:02:57Documente românești false, lipite pe piciorul unui cetățean moldovean. Au fost găsite de polițiștii de frontieră —» Elena Robu
08:41:14Copii de astăzi sunt viitorii antreprenori de mâine – Avem nevoie de un alt sistem de învățământ? —» Liapogolsa.eu - Atrage energie, succes si banii in viata TA
07:56:24O moldoveancă și un italian exploatau 10 „badante” în Italia —» Elena Robu
07:19:12Un vin de mare medalie de aur —» Fine Wine
07:00:32Șoferul cu BMW și locul pentru persoanele cu handicap —» Cojocari Vitalie