0% found this document useful (0 votes)
10 views

Code Listings1

Uploaded by

mbsysde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Code Listings1

Uploaded by

mbsysde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

11/16/24, 10:56 PM C# in a Nutshell - Code Listings

Chapter 2 - C# Language Basics


A First C# Program
A First C# Program

int x = 12 * 30; // Statement 1


System.Console.WriteLine (x); // Statement 2

A First C# Program with using directive

using System;

int x = 12 * 30; // Statement 1


Console.WriteLine (x); // Statement 2

First Program Refactored

// Here, we've refactored the logic in our original main method into a method called FeetToInches.

Console.WriteLine (FeetToInches (30)); // 360


Console.WriteLine (FeetToInches (100)); // 1200

int FeetToInches (int feet)


{
int inches = feet * 12;
return inches;
}

Method with no input or output

SayHello();

void SayHello()
{
Console.WriteLine ("Hello, world");
}

A First C# Program - without top-level statements

using System;

class Program
{
static void Main()
{
Console.WriteLine (FeetToInches (30)); // 360
Console.WriteLine (FeetToInches (100)); // 1200
}

static int FeetToInches (int feet)


{
int inches = feet * 12;
return inches;
}
}

Syntax Basics

Type Basics

Numeric Types

Boolean Type and Operators

Strings and Characters

Arrays

Variables and Parameters

Expressions and Operators

Null Operators

Statements

Namespaces

https://w w w .albahari.com/nutshell/E12-CH02.aspx 1/2


11/16/24, 10:56 PM C# in a Nutshell - Code Listings

C# 12
in a Nutshell
About the Book

Code Listings
C# 12 in a Nutshell
C# 10 in a Nutshell
C# 9.0 in a Nutshell
C# 8.0 in a Nutshell
C# 7.0 in a Nutshell

Extras

Contact

Buy print or Kindle edition

Buy PDF edition

Read via O'Reilly subscription

https://w w w .albahari.com/nutshell/E12-CH02.aspx 2/2

You might also like