C# Console Application

Slides:



Advertisements
Similar presentations
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Advertisements

Computer and Programming
Arrays. What is an array An array is used to store a collection of data It is a collection of variables of the same type.
Introduction to Programming Lesson 1. Objectives Skills/ConceptsMTA Exam Objectives Understanding Computer Programming Understand computer storage and.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Objectives You should be able to describe:
Chapter 7: Working with Arrays
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Java. Why Java? It’s the current “hot” language It’s almost entirely object-oriented It has a vast library of predefined objects It’s platform independent.
.Net Training Lecture – 1 Author: Suhrid Patel. What is.NET ? It is a platform neutral framework. Is a layer between the operating system and the programming.
High-Level Programming Languages: C++
Its all just code by group 8 张亚东,杨杰,甘伟,余青龙,肖春亮 chapter 2.
CIS Computer Programming Logic
Iteration and Simple Menus Deterministic / Non-deterministic loops and simple menus.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
COIT29222 Structured Programming Slide 1 COIT29222-Structured Programming Lecture Week 06  Reading: Study Guide Book 2, Modules 9 & 10 Textbook (4 th.
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
Computer Science 12 Mr. Jean May 2 nd, The plan: Video clip of the day Review of common errors in programs 2D Arrays.
Flow of Control Part 1: Selection
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
1 C# A brief overview by Jack Senechal and Bryan Powell.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
C# Programming Fundamentals Control Flow Jim Warren, COMPSCI 280 S Enterprise Software Development.
CPS120: Introduction to Computer Science Decision Making in Programs.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
COP-3330: Object Oriented Programming Flow Control May 16, 2012 Eng. Hector M Lugo-Cordero, MS.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
Controlling Execution Dong Shao, Nanjing Unviersity.
Research Topics in Computational Science. Agenda Survey Overview.
Computing with C# and the.NET Framework Chapter 3 Software Engineering with Control Structures.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
CSE 110 Review Session Hans Hovanitz, Kate Kincade, and Ian Nall.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
Session 1 C# Basics.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Flow of Control: Loops Module 4. Objectives Design a loop Use while, do, and for in a program Use the for-each with enumerations Use assertion checks.
Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Engineering Computing I Chapter 3 Control Flow. Chapter 3 - Control Flow The control-flow of a language specify the order in which computations are performed.
Arrays and Loops. Learning Objectives By the end of this lecture, you should be able to: – Understand what a loop is – Appreciate the need for loops and.
Unit – 3 Control structures. Condition Statements 1.If.…..else :- Has someone ever told you, "if you work hard, then you will succeed"? And what happens.
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Introduction to Programming Lesson 1. Algorithms Algorithm refers to a method for solving problems. Common techniques for representing an algorithms:
Presentation By :- Nikhil R. Anande ( ) Electronic & Communication Engineering. 3 nd Year / 5 th Semester FACULTY GUIDE : RAHIUL PATEL SIR MICROCONTROLLER.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
MIS Professor Sandvig MIS 324 Professor Sandvig
Java for Android is specific
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
ITM 352 Flow-Control: Loops
MIS Professor Sandvig MIS 324 Professor Sandvig
For Loops October 12, 2017.
Topic 1: Problem Solving
Objectives You should be able to describe: The while Statement
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Introduction to Programming
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Presentation transcript:

C# Console Application C# syntax Overview

C# Syntax The following sample shows different ways you can declare a variable: int a; int salary, income Tax, sum; int count = 10; string name; string fullName= "Little John";

C# Syntax Loop Statements while int i = 0; while ( i < 5 ) { Console.WriteLine ( i ); ++i; } The above loop repeates 5 times and prints the value of i. The output of above code would be like this : 0 1 2 3 4

C# Syntax for for ( int i = 0; i < 5; i++ ) { Console.WriteLine ( i ); } The above loop repeates 5 times just like the while loop and prints the value of i. The output of above code would be like this : 0 1 2 3 4

C# Syntax do ... while int i = 0; do { Console.WriteLine ( i ); i++; } while ( i < 5 ); The above loop is pretty much same as the while loop. The only difference is, the condition is checked only after executing the code inside the loop.

C# Syntax foreach string [] names = new string[]{ "Little John", "Pete", "Jim", "Bill" }; foreach ( string name in names ) { Console.WriteLine ( name ); } foreach loop can be used to iterate through a collection like array, ArrayList etc. The above code displays the following output: Little john Pete Jim Bill

C# Syntax Conditional Operators if ... else This is the conditional operator, used to selectively execute portions of code, based on some conditions. string name = "Little John"; if ( name == "Jim" ) { Console.WriteLine( "you are in 'if' block" ); } else { Console.WriteLine( "you are in 'else' block" ); } in the above case, it prints : you are in 'else' block

C# Syntax Flow Control Statements break 'break' statement is used to break out of loops ('while', 'for', switch' etc). string [] names = new string[] { "Little John", "Pete", "Jim", "Bill" }; foreach ( string name in names ) { Console.WriteLine ( name ); if ( name == "Pete" ) break; } In the above sample, it iterates through the array of 4 items, but when it encounters the name "Pete", it exits the loop and will not continue in the loop anymore. The output of above sample would be : Little John Pete

C# Syntax continue 'continue' statement is also used to in the loops ('while', 'for' etc). When executed, 'continue' statement will move the exection to the next iteration in the loop, without continuing the lines of code after the 'continue' inside the loop. string [] names = new string[]{ "Little John", "Pete", "Jim", "Bill" }; foreach ( string name in names ) { if ( name == "Pete" ) continue; Console.WriteLine ( name ); } In the above sample, when the value of name is "Pete", it executes the 'continue' which will change the execution to the next iteration, without executing the lines below it. So, it will not print the name, if the name is "Pete". The output of above sample would be : Little John Jim Bill

C# Syntax switch if you have to writeseveral if...else conditions in your code, switch statement is a better way of doing it. The following sample is self explanatory: int i = 3; switch ( i ) { case 5: Console.WriteLine( "Value of i is : " + 5 ); break; case 6: Console.WriteLine( "Value of i is : " + 6 ); break; case 3: Console.WriteLine( "Value of i is : " + 3 ); break; case 4: Console.WriteLine( "Value of i is : " + 4 ); break; default: Console.WriteLine( "Value of i is : " + i ); break; }

C# Syntax In the above sample, depending on the value of the conditional item, it executes appripriate case. In our code, since the value of i is 3, it executes the third case. The output will be as shown below: Value of i is : 3

New Topic Data Type in C#

Data type in c# DataTypes are the basic building block of any language. Microsoft has tried to standardise the datatypes in .NET framework by introducing a limited, fixed set of types that can be used to represent almost anything in programming world. C++ was very rich in datatypes, but that leads to confusion too. Especially, when you write components that may be consumed by applications written in other platforms, you have to make sure the types used are compatible with other platforms too!

Data type in c# .NET types start from a clean slate. All .NET languages share the same types. They are all compatible and no worries. This means, you can call C# code from VB.NET and vice versa, without worrying about type conversions.

Data type in c# .NET data types are either structures or classes, part of the System namespace. For example, the following data types are implemented as struct in .NET: Int16 Int32 Double (String is implemented as a class in .NET, for various reasons.) If you are not very familiar with struct and class, don't worry about it. You can just use them as if they are simple data types.

Data type in c# Here is how you can declare variables of type Int, Double and String: Int16 age, employeeNumber; Double salary; String name, address;

Data Type in C# You can use any of the .NET data types directly in any .NET language - in C#, VB.NET or xyz.NET. But in addition to the .NET types, each language provides a set of primitive types, which map to the corresponding types in .NET class library. This is why you may see some people use string and some others use String. There is no big difference. string is a primitive data type in C# and String is the corresponding class in .NET class library The string in C# is mapped to the class in .NET class library. So, whether you use string or String, there is no real difference. The following list shows the list of data types available in C# and their corresponding class/struct in .NET class library

Data type in c#

Data type in c# In C# data types are classified into two : value types reference types The following tables shows some of the differences between values types and reference types.

Data type in C#