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

22:29:00Despre chat GPT și inteligența artificială. —» Blog de Cultura
15:43:48Autobuz Euro 6 care scoate fum ca tractorul —» Curaj.TV | Media alternativă
14:00:00Sell Courses and Create Interactive Content on WordPress.com —» Ileana Pîrgaru
07:34:40ALEXANDRU COSMESCU - MENTOR AL TINERILOR SCRIITORI BASARABENI —» Andrei LANGA. Blogul personal
05:59:40Solidari cu puterea? —» Curaj.TV | Media alternativă
18:22:39Poliție fără centuri pe Șoseaua Panduri —» Curaj.TV | Media alternativă
18:06:14Making the Social Web a Better Place: ActivityPub for WordPress Joins the Automattic Family  —» Ileana Pîrgaru
09:36:34O CARTE ÎN PERCUȚII DE ECOU... —» Leo Butnaru
22:23:55O conversaţie cu ChatGPT despre ChatGPT —» APort | "Pentru un român care știe citi, cel mai greu lucru e să nu scrie." I.L. Carag
20:52:44Activiști atacați cu spray de un paznic, cu poliția de față —» Curaj.TV | Media alternativă
18:29:08Poliția, cu mașina pe trotuar, amendează pentru același lucru —» Curaj.TV | Media alternativă
18:24:31Protest al foștilor revoluționari în Piața Universității —» Curaj.TV | Media alternativă
09:40:59Valorificarea operei hasdeistice, digitizată din Colecția „Carte veche și rară” a Bibliotecii Centrale a BM „B.P. Hasdeu”: Expoziție aniversară (1) —» BiblioCity
09:40:32Valorificarea operei hasdeistice, digitizată din Colecția „Carte veche și rară” a Bibliotecii Centrale a BM „B.P. Hasdeu”: Expoziție aniversară (2) —» BiblioCity
06:22:05Raport analitic anual 2022 Bibliotecile Publice Teritoriale din Raionul Rîșcani —» Biblioteca Publică or.Rîşcani
22:56:41Tânăr pensionar, caut sponsor! —» APort | "Pentru un român care știe citi, cel mai greu lucru e să nu scrie." I.L. Carag
14:33:29Fii ecologic! Reciclează corect! —» BiblioCity
19:47:36A Social Experience Anchored by Your Domain —» Ileana Pîrgaru
08:32:56Cel mai bun cașcaval din lume, la Purcari Wine Bar —» Fine Wine
08:14:11LECTURA – CEA MAI IMPORTANTĂ ȘI CAPTIVANTĂ PASIUNE A OMULUI. —» Biblioteca Publică or.Rîşcani
07:24:07VALOAREA PROFESIEI DE BIBLIOTECAR —» Biblioteca Publică or.Rîşcani
22:19:00Efectele telefonului mobil asupra copilului. —» Blog de Cultura
22:03:00Cum alegi un psiholog bun? —» Blog de Cultura
21:42:56Harald Jähner – Aftermath. Life in the fallout of the third reich —» APort | "Pentru un român care știe citi, cel mai greu lucru e să nu scrie." I.L. Carag
20:08:00Deținuți de la Soroca, reclamă abuzuri ale gardienilor —» Curaj.TV | Media alternativă