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
❑ 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,
using System;
namespace Wrox.ProCSharp.Basics
class MyFirstCSharpClass
static void Main()
Console.WriteLine(“This isn’t at all like Java!”);
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.

2007-07-14 20:04:00


Ultimele 25 posturi adăugate

05:30:06Sergiu Litvinenco revine pe calea cea dreaptă? —» un alt blog
13:32:05Blonde —» APort | "Pentru un român care știe citi, cel mai greu lucru e să nu scrie." I.L. Carag
18:08:28Solidaritate cu femeile revoltate din Iran. Protest la București —» Curaj.TV | Media alternativă
17:52:43Mărieș mă alungă în Rusia, a privatizat km0!? —» Curaj.TV | Media alternativă
21:16:12Zice că surorile și bărbatul i-au luat ilegal fiica —» Curaj.TV | Media alternativă
20:31:12Am pus poliţia la treabă pentru o cauză verde —» Curaj.TV | Media alternativă
14:57:12SuntMAMĂ răspunde la Chestionarul lui Marcel Proust —» Sunt MAMĂ!
06:19:47Ortodoxia dragostei, ortodoxia urii și talibanul Kirill —» blog cultural
05:43:18Ministrul Gaibu: reforme de dragul unui milionar din Tvardița, îmbogățit pe spirt, tutun și carne din Brazilia —» un alt blog
19:39:56Și după închiderea Duty Free câte judecate internaționale vor urma? —» un alt blog
18:09:53What’s New in the Editor: More Design Tools, Enhanced Lists, Easier Block Switching —» costica
13:59:00Opera GX teams up with TikTok for the #GamingForAll challenge feat. BlindWarriorSven, challenging gamers to defy their limitations —» Luchian Alexandru
11:58:56Retrospectivă. Simpozionul Național de Studii Culturale. Ediția a IV-a —» Biblioteca de Arte 'Tudor Arghezi'
10:38:35Spînu face rublet cu rușii dar cere ajutor de la România… // Despre păcură —» un alt blog
06:58:33Am zis să nu mai „ating” politicul din RM, dar a ieșit Angela Merkel și ne-a avertizat să nu ne jucăm cu putin. Și m-a enervat, mama mă-sii! —» nimic nu e asa cum pare a fi...
05:43:21Faceți cunoștință: Corina Gaibu, ONGistă, vicepreședinte de partid, soție de ministru și abonată la rublet din buget —» un alt blog
17:18:18Pledoarie pentru pedalare, ca să respirăm mai ușor —» Curaj.TV | Media alternativă
17:14:29Accident cu mașini bengoase pe lîngă pădurea Băneasa —» Curaj.TV | Media alternativă
17:08:19Se împart amenzi la piața de flori Coșbuc —» Curaj.TV | Media alternativă
15:29:02Nu mai aruncați chiștoace pe oriunde, se adună greu! —» Curaj.TV | Media alternativă
11:43:34„Mica enciclopedie Ikigai” de Ken Mogi —» Sunt MAMĂ!
09:01:53Nou: Piatra Neagră 2017 Chateau Cojusna —» Fine Wine
06:38:19E mult sau puțin o casă nouă de peste 600 de mii de Euro pentru ministrul economiei? —» un alt blog
18:17:02God is Always with us —» Erik and Elena Brewer's Weblog
09:05:38DIN MAREA POEZIE A LUMII —» Leo Butnaru