0% found this document useful (0 votes)
22 views6 pages

C# Programming Day 02

The document covers key concepts in C# programming, including the use of namespaces to organize related classes and the declaration of variables with specific data types. It also discusses naming conventions for variables and the introduction of the 'var' keyword for implicitly typed local variables. Additionally, it touches on decision-making statements like if, else if, and else for controlling program flow based on logical conditions.

Uploaded by

Eric Mboya
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)
22 views6 pages

C# Programming Day 02

The document covers key concepts in C# programming, including the use of namespaces to organize related classes and the declaration of variables with specific data types. It also discusses naming conventions for variables and the introduction of the 'var' keyword for implicitly typed local variables. Additionally, it touches on decision-making statements like if, else if, and else for controlling program flow based on logical conditions.

Uploaded by

Eric Mboya
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/ 6

C# PROGRAMMING

DAY 02 (25 July 24, 2024)

C# Namespace
Namespaces play an important role in managing related classes in C#. The .NET
Framework uses namespaces to organize its built-in classes. For example, there
are some built-in namespaces in .NET such as System, System.Linq, System.Web,
etc. Each namespace contains related classes.

A namespace is a container for classes and namespaces. The namespace also


gives unique names to its classes thereby you can have the same class name in
different namespaces.

In C#, a namespace can be defined using the namespace keyword.

Another Example, the namespace contains two classes.


Example: Refer a Class with Namespace
A namespace can contain other namespaces. Inner namespaces can be
separated using (.)

Example: C# 10 Namespace

C# Variables
In C#, a variable stores a value of the specific data type. It can store a numeric,
char, string, or other types of value. You can declare and assign a value to a
variable like int x = 5; where int is the data type, x is the name of a variable, = is
an operator that assigns the value to a variable, and 5 is the integer value
assigned to a variable x.
The followings are naming conventions for declaring variables in C#:

• Variable names must be unique.

• Variable names can contain letters, digits, and the underscore _ only.

• Variable names must start with a letter.

• Variable names are case-sensitive, num and Num are considered


different names.

• Variable names cannot contain reserved keywords. Must prefix @ before


keyword if want reserve keywords as identifiers.

NOTE

It is not necessary to specify the specific type when declaring variables. Use
the var keyword instead of a data type.

C# - var

In C#, variables must be declared with the data type. These are called explicitly
typed variables.

Example: Explicitly Typed Variable

C# 3.0 introduced var keyword to declare method level variables without


specifying a data type explicitly.

Example: Implicitly Typed Local Variable


C# - Data Types

C# is a strongly-typed language. It means we must declare the type of a variable


that indicates the kind of values it is going to store, such as integer, float, decimal,
text, etc.

C# CONDITIONS & LOOPS

1. C# - if, else if, else Statements

C# provides many decision-making statements that help the flow of the C#


program based on certain logical conditions. Here, you will learn about if, else if,
else, and nested if else statements to control the flow based on the conditions.

You might also like