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

20:59:44Fără Titlu —» Путепроводные Заметки
20:57:02Fără Titlu —» Путепроводные Заметки
15:17:57Felicitare la Finalul Anului Școlar 2024 -2025 —» Liceul Teoretic “Mihail Sadoveanu”, Călăraşi
10:27:31Fără Titlu —» Путепроводные Заметки
16:57:30Fără Titlu —» Путепроводные Заметки
14:57:00Cum recunoști un text scris de AI, dar neredactat de om - ghid pentru cititori și jurnaliști —» Eleonora Lisnic în versuri
13:43:00ATENȚIE la înșelătoriile online! Cursurile serioase de Inteligență Artificială sunt organizate de instituții acreditate —» Eleonora Lisnic în versuri
13:20:16Fără Titlu —» Путепроводные Заметки
07:17:36300 de invitați sunt așteptați, în iunie la Chișinău, la Congresul mondial al vinului —» Fine Wine
06:42:41Ce înseamnă „Eu sunt cu voi şi nimeni împotriva voastră”? —» Portalul Tineretului Ortodox din Moldova
04:42:53Fără Titlu —» Путепроводные Заметки
14:48:42Anunț de contractare a furnizorilor de echipamente și utilaje în cadrul proiectului „Abilitarea tinerilor antreprenori din Republica Moldova” —» Asociaţia Obştească "Demos"
13:49:13Fără Titlu —» Путепроводные Заметки
11:27:11Muzică de Fanfara —» CHIŞINĂU MUZICAL | Blogul Bibliotecii de Arte "Tudor Arghezi"
10:09:32Vinul care face bine: Sapiens —» Fine Wine
08:42:06Invitație la tender: Servicii de instruire și mentorat pentru tineri antreprenori din regiunea de nord a Republicii Moldova —» Asociaţia Obştească "Demos"
08:41:07Crama Neamțu lansează recolta 2024 —» Fine Wine
07:44:02#DirectEuropa‬ cu Ileana Răcheru —» Curaj.TV | Media alternativă
04:49:40Fără Titlu —» Путепроводные Заметки
20:40:00Kinderland —» Andrei LANGA. Blogul personal
20:40:00Kinderland —» Andrei LANGA. Blogul personal
13:50:29Fără Titlu —» Путепроводные Заметки
13:41:00Măr —» Andrei LANGA. Blogul personal
13:41:00Măr —» Andrei LANGA. Blogul personal
11:46:00Prompt AI - exemplu util, simplu și adaptabil. GhatGPT explică editarea unui video în CapCut —» Eleonora Lisnic în versuri