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

Lecture 02 - programming fundamentals

Uploaded by

anjalee himalki
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)
15 views

Lecture 02 - programming fundamentals

Uploaded by

anjalee himalki
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/ 17

Language Fundamentals

Object oriented with visual


programming
M. Y. A Rahman
Console class
Console class
 Command-based input/output operations in C# by using the console class.
 These are application run in a command window
 The console class provides a C# application with access to this:
 Standard input
 Standard output
 Standard error streams
Namespace
 Contain groups of code that can be called upon by C# programs.
 The .Net Framework class Library(FCL) organized in a hierarchical tree structure and it
is divided into Namespace. Namespace is a logical grouping of types for the purpose
of identification.
 Using system
 Telling the program that it can reference the code in the system namespace without pre-
pending the word system to every reference.
First C# program with Console
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;

 namespace consoleprogram1
 {
 internal class Program
 {
 static void Main(string[] args)
 {
 //Write to console
 Console.WriteLine("Hello world!");
 //Hold the screen
 Console.ReadLine();
 }
 }
 }
Variables and data types

 A variable is nothing but a name given to a storage are that our programs can
manipulate.
 Each variable in C# has a specific type, which determines the size and layout of the
variable’s memory; the range of value that can be stored within that memory; and
the set of operations that can be applied t0 the variable.
Getting Interactive Input/output
note: Remember C# is case sensitive.
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;

 namespace consoleprogram2
 {
 internal class Program
 {
 static void Main(string[] args)
 {
 Console.WriteLine("What is your name :");
 String name = Console.ReadLine();

 //place holder{0} for the variable: can have more than one
 Console.Write("Hello {0} ", name);
 Console.WriteLine("Welcome to C#!!!");
 //makes the program wait for a key press and it prevents the screen until a key is pressed
 Console.ReadKey();
 }
 }
 }
Program 3: Write a simple console
application to get an output as below

************
Enter name: M.D Silva
Enter Index No: HD142100
xxxxxxxxxxxxxxxxxx
Your name is: M.D Silva
Index no: HD142100
xxxxxxxxxxxxxxxxxxx
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;

 namespace consoleprogram3
 {
 internal class Program
 {
 static void Main(string[] args)
 {
 Console.WriteLine("Enter name: ");
 string name = Console.ReadLine();
 Console.WriteLine("Enter ID no: ");
 String idno = Console.ReadLine();

 Console.WriteLine("*********");
 Console.WriteLine("Your name: {0} ", name);
 Console.WriteLine("Index no: {0} ", idno);
 Console.WriteLine("*********");

 Console.ReadLine();

 }
 }
}
Program 4: A console program to find
addition, subtraction, multiplication and
division of two variables
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;

 namespace consoleprogram4
 {
 internal class Program
 {
 static void Main(string[] args)
 {
 int n1, n2, result; float fresult;
 Console.WriteLine("Enter first number: ");
 n1 = Convert.ToInt32(Console.ReadLine()); //because it thinks all inputs are string

 Console.WriteLine("Enter second number: ");


 n2 = Convert.ToInt32(Console.ReadLine());

 Console.WriteLine("----Answer----");
 result = n1 + n2;
 Console.WriteLine("Addition of the two numbers are: {0} ", result);
 result = n1 - n2;
 Console.WriteLine("Substraction of the two numbers are: {0} ",
result);
 result = n1 * n2;
 Console.WriteLine("Multiplication of the two numbers are: {0} ",
result);
 fresult = n1 / n2;
 Console.WriteLine("Division of the two numbers are: {0} ",
fresult);

 Console.ReadLine();
 }
 }
 }
Write a console program to get the ODD and Even numbers from 1-50
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;

 namespace consoleprogram5
 {
 internal class Program
 {
 static void Main(string[] args)
 {
 for(int c=1; c<=50; c++)
 {
 int r = c % 2;
 if(r == 0)
 {
 Console.WriteLine("{0} is an Even Number:", c);
 }
 else
 {
 Console.WriteLine("{0} is an Odd number: ", c);
 }
 Console.ReadKey();
 }
 }
 }
 }
Language concept
OOP’s Overview
 OOP – The core ingredient of the .NET framework.
 The fundamental idea behind OOP
 Combine into a single unit(data & methods).
 Such units are called an object.
 All OOP languages provide mechanisms help to implement the object oriented
models
 Encapsulation
 Inheritance
 Polymorphism
 Reusability

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy