C# Basic Constructs: Visual Programming
C# Basic Constructs: Visual Programming
C# Basic Constructs
Visual Programming
• Introduction
• Data Types
• Variables
• Constants
• Conditional Statement
• Loops
• Jump Statement
Introduction
• This lreect explores the core C# programming language
construct by presenting numerous stand-alone
concepts, such as data types, constants, iterations and
conditional statements. It describes the various data
types provided by the .NET Framework.
• It also investigates the various loop constructs in depth
and takes a closer looks at conditional statements.
• By the end of this lecture you will have a sufficient
understanding of C# enough to write rudimentary
programming constructs without using advanced
object-oriented features.
1. Data Types
• Like any programming language C# uses data types to
represent a variable.
• The CLR provides the two categories of data types,
Value Type and Reference Type. Both types are stored
in different types of memory; a value type stores its
value in the stack and a reference type stores a
reference to the value in the managed heap.
• Now the question becomes, how to determine
whether a type it is a value type or a reference type.
• For example int is a value type and a class object is a
reference type.
1. Data Types
• In the following example int a and b create
two memory slots declaring an int variable
and assigns them a value of another int type
variable, you have two separate int values in
memory.
1. Data Types
• Whereas, in the reference type a different
picture exists.
• In the following code, the class test is used in
the creation of an object that is a reference
type:
• The important point to understand here is
that a test class revolves around objects only.
obj1 and obj2 are variables of a reference type
and both point to the same location that
contains this object.
Value Type
• The value types have several type
subcategories. The important point to note is
that these are built into the language. The
predefined type names all start with
lowercase letters.
Variables
• Variables are special containers that hold
some data at specific memory locations.
• Variables can either be numeric, string, date,
character, Boolean and so on. A variable can
be declared with the following syntax in C#:
3. Constants
Assignment
1. Write a program in C# Sharp to display the first
10 natural numbers
• Expected Output :
1 2 3 4 5 6 7 8 9 10
2. Write a C# Sharp program to find the sum of first
10 natural numbers.
Expected Output :
The first 10 natural number is :
1 2 3 4 5 6 7 8 9 10
The Sum is : 55
Assignment
3. Write a program in C# Sharp to display n
terms of natural number and their sum
Assignment
4. Write a program in C# Sharp to read 10
numbers from keyboard and find their sum and
average.
5.Write a program in C# Sharp to display the
cube of the number up to given an integer.