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

15:21:21Top vânzări carte pentru copii, noiembrie 2019. Librăriile Cartier —» Gheorghe Erizanu
15:02:08În vizită la Auschwitz, cancelarul german Angela Merkel îşi exprimă ”ruşinea profundă” —» Elena Robu
14:38:59Cu cât vor crește salariile în 2020 —» Elena Robu
12:11:14De ce să nu ne mai victimizăm! —» Victor Timotin | creează, inovează, dezvoltă și fii exemplu
11:39:31Protestează la PG și MAI contra popii din sat —» Curaj.TV | Media alternativă
11:20:11Servicii funerare scumpe, dar fără acte legale —» Curaj.TV | Media alternativă
11:18:21Sofa Mart Denver —» Andrei Fornea
11:14:48Vin’ la vânat —» Fine Wine
10:03:43Анонс: Официальная трибьют-группа "КИНО" - группа "ВИКТОР" выступит с концертом "30 лет альбому "ГРУППА КРОВИ" —» Заметки Начинающего Журналиста
09:42:14Легенда джазовой музыки, композитор и пианист Леонид Чижик: «Я – кишиневец» —» Заметки Начинающего Журналиста
07:41:39Leo BUTNARU - POEME —» Leo Butnaru
07:39:35Lisa Marie Fernandez —» Andrei Fornea
07:33:53Când se va împlini săptămâna a șaptezecea din Daniel? —» Moldova Creștină
06:38:21Cum mi-a învinețit Ilinca degetul de la picior —» Andrei Albu - omul alb cu gînduri negre
04:00:18Felicitarea de Crăciun —» Viata pe Tinder – Viata amoroasa pe Tinder
20:11:13Inside the Organized Crime Syndicate known as the CIA: an Interview with Douglas Valentine —» ajna-blogging-press
19:33:11Are de hrănit 5 copii singură, soțul și statul nu o ajută —» Curaj.TV | Media alternativă
19:30:00Cenaclul „Prietenii muzelor” —» Biblioteca de Arte 'Tudor Arghezi'
19:28:08Jared Diamond – UPHEAVAL – How nations cope with crisis and change —» APort | "Pentru un român care știe citi, cel mai greu lucru e să nu scrie." I.L. Carag
17:13:45O greșeală, pe care o facem când suntem tineri. —» Victor Timotin | creează, inovează, dezvoltă și fii exemplu
17:08:31Protestează la Președinție de grija copiilor —» Curaj.TV | Media alternativă
16:03:27Vine Moș Niculae. 50 la sută reduceri pentru cărțile Cartier —» Gheorghe Erizanu
15:16:45Ce va fi la vamă cu Sergiu Burduja în frunte și când va depune mărturii la procuratură Balițchi? —» un alt blog
15:03:32Donald Trump va fi pus sub acuzare de Camera Reprezentanţilor —» Elena Robu