Cover | Table of Contents | Colophon
if, while,
and for. You'll learn about these
keywords in the coming chapters.
namespace NotePad
{
class HelloWorld
{
// every console app starts with Main
static void Main()
{
System.Console.WriteLine("Hello world!");
}
}
}
namespace NotePad
{
class HelloWorld
{
// every console app starts with Main
static void Main()
{
System.Console.WriteLine("Hello world!");
}
}
}csc HelloWorld.cs
namespace NotePad
{}).
Thus, the second line of the Hello World program is an open brace to
mark the beginning of the NotePad namespace. The open brace is
matched by a closing brace at the end of the program.
class Dog
{
private int weight; // member field
private String name; // member fieldclass Dog
{
private int weight;
private String name;
public void bark()
{
// code here to bark
}
public and
private are known as access
modifiers, which are used to specify what classes can
access particular members. For instance, public members can be called
from methods in any class, while private members are visible only to
the methods of the class that defines the member. Thus, objects of
any class can call bark on a Dog, but only methods of Dog have access
to the weight and name of the Dog. Access modifiers are discussed in
Chapter 8.
|
Type
|
Size (in bytes)
|
.NET type
|
Description
|
|---|---|---|---|
|
byte
|
1
|
Byte
|
Unsigned (values 0-255).
|
|
char
|
2
|
Char
|
Unicode characters.
|
|
bool
|
1
|
|
Type
|
Size (in bytes)
|
.NET type
|
Description
|
|---|---|---|---|
|
byte
|
1
|
Byte
|
Unsigned (values 0-255).
|
|
char
|
2
|
Char
|
Unicode characters.
|
|
bool
|
1
|
Boolean
|
True or false.
|
|
sbyte
|
1
|
SByte
|
Signed (values-128 to 127).
|
|
short |
int myVariable = 15;
int myVariable;
int myVariable; // some other code here myVariable = 15; // assign 15 to myVariable
int myVariable; // some other code here myVariable = 15; // assign 15 to myVariable // some other code here myVariable = 12; // now it is 12
int myInt;
class Values
{
static v