Presentation is loading. Please wait.

Presentation is loading. Please wait.

C# Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital.

Similar presentations


Presentation on theme: "C# Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital."— Presentation transcript:

1 C# Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Suhardi.suhaimi@pb.edu.bn Digital Media Department Politeknik Brunei

2 Introduction to Programs Programs Development Programming Errors Introduction to C# C# Features Compilation Types of C# Program 2 Contents 2

3 Visual Studio Express 2012 (IDE) A First C# Program Analyzing The Program C# identifiers Naming Identifier C# Reserved Keywords 3 Contents Cont. 3

4 Variables Assignment Using Value Types Variable Constant Naming Conventions 4 Contents Cont. 4

5 Programs – a set of instructions written to perform a specific task with a computer. Programs are stored permanently in secondary memory (e.g. on hard disk). Instruction are encoded as binary numbers (machine code). When a program is to be run, it copied (loaded) into main memory, and the CPU executes the instructions of the program. Introduction to Programs 5

6 Program may read data from secondary memory and input devices. Through flow-control (If-Else, Loops, do-While,etc) the program can control the order in which program instructions are executed. Program data (variables) are stored in main memory. Results are written to output devices or to secondary memory. Introduction to Programs Cont. 6

7 Editor - Allows the creation of a file with your program. Compiler - A program that translates the source code into machine code. Source Code – A program written in high-level language. High-level languages – English-like statements that is easy to learn and program. Programs Development 7

8 Interpreter – Similar to compiler but a small part of source code is translated and executed before next part is translated. Syntax – Rules of grammar and vocabulary of a language. Semantics – the meaning of something written in the language. A program can be syntactically correct but semantically incorrect. We want programs that are syntactically and semantically correct. Programs Development Cont. 8

9 There are few types of programming errors Compile-time error – generated when the compiler cannot resolve a problem in the source code while it is compiling. Runtime error – generated when execution of a particular code statement or function results in an error condition being set. Logic error - program may be successfully compile but does not behave as intended. Only clue to the error is production of wrong solutions. Programming Errors 9

10 C# (pronounced as C Sharp) is an object oriented programming language that fully supports the functionality of the.NET framework. The language name is inspired by the musical note C# which is a “step above” C/C++ C# can be used to develop windows applications, web applications using ASP.NET, web services and others. Introduction to C# 10

11 C# is originated by Microsoft as a response to Java Microsoft state that C# is a language with the power of C++ and the simplicity of Visual Basic. Its initial public release is in 2000. The lead designers of C# are: Anders Hejlsberg Scoot Wiltamuth Introduction to C# Cont. 11

12 Variables in C# are automatically initialized by the environment. Variables are type-safe Native support for the component object model (COM) and windows-based APIs. Built in versioning Restricted use of native pointers with C#, every object is automatically a COM object. C# Features 12

13 Compiler allows use of initialised Variables only Strong exception handling Full XML support Suited well for building Web Services The language is intended for use in developing software components suitable for deployment in distributed environments. C# Features Cont. 13

14 Ultimately, developing applications using C# is usually done with an Integrated development Environment (IDE) such as Visual Studio Integrated development environment (IDE) – Combines editor, compiler and other tools into a single application. We can also use csc.exe – a command line (on DOS) compiler Compilation 14

15 Console Applications – Stand-alone program using a command-line interface. Types of C# Program 15

16 Windows Applications – Stand-alone programs using a Graphical User Interface (GUI). Types of C# Program Cont. 16

17 Silverlight Applications – a cross-platform next generation.NET based media with rich interactive applications for the Web. Types of C# Program Cont. 17

18 ASP.NET Web Applications – are Web applications displayed in a Web browser, instead of on a console or in a forms application. Types of C# Program Cont. 18

19 ASP.NET Web Service Applications – to create services that can be accessed by using URLs, HTTP, and XML. Types of C# Program Cont. 19

20 Smart Device Applications – use to create applications that run on mobile devices, such as PDAs and Smartphones. Smart device applications can be console applications, Windows Forms applications, or in a Web browser. Types of C# Program Cont. 20

21 Visual Studio Express 2012 (IDE) 21

22 A First C# Program 22 Class name Main method Comments String

23 The first thing to note about C# is that it is case- sensitive. You will therefore get compiler errors if, for instance, you write console rather than Console. The second thing to note is that every statement finishes with a semicolon ( ; ) or else takes a code block within curly braces ( { ). A First C# Program Cont. 23

24 Line 7-10 These lines are comments and ignored by the compiler  Comments helps programmers to communicate and understand the program. Line 7 is a single line comment preceded by two slashes ( // ) Line 8-10 are multiple line comments enclosed between /* and */ on one or several lines. Analyzing The Program Cont. 24

25 Identifiers are names used to denote variables, constants, types, methods, objects, and so on. An identifier begins with a letter or an underscore and ends with the character just before the next white space. C# identifiers are case sensitive. For example, three variables myVar, MyVar and MYVAR are all different. C# Identifiers 25

26 Before you can use a variable in a program, you must declare it which means you must give a name (identifier) to it and how much space to use. For example: int age; Rules to follow when naming an identifier: The name must start with a letter or an underscore. After the first letter or underscore, the name can have letters, digits, and/or underscores. Naming Identifier 26 Type Identifier

27 The name must not have any special characters other than the underscore. The name cannot have a space. Note that C# is case sensitive. It cannot be true, false or null Avoid using C# reserved keywords. Naming Identifier Cont. 27

28 Example If the rules are not obeyed, the compiler will report a syntax error. Naming Identifier Cont. 28 Allowable NamesIllegal names amountPaidreturn pay20082008pay heightOfBox

29 C# Reserved Keywords 29 abstractconstexternintoutshorttypeof ascontinuefalseinterfaceoverridesizeofuint base decima l finallyinternalparamsstackalloculong booldefaultfixedisprivatestaticunchecked breakdelegatefloatlockprotectedstringunsafe bytedoforlongpublicstructushort casedoubleforeachnamespacereadonlyswitchusing catchelsegotonewrefthisvirtual charenumifnullreturnthrowvoid checkedeventimplicitobjectsbytetruevolatile classexplicitinoperatorsealedtrywhile getpartialsetvaluewhereyield

30 Variables are simply storage location for data. Data can be placed into the variables and retrieve their contents as part of a C# expression. The interpretation of the data in a variable is controlled through Data Types. Variables 30

31 The syntax for declaring a variable: datatype variableName ; Example Variables Cont. 31 int x; //Declare x to be an integer variable double radius; //Declare radius to be a double variable double interestRate; //Declare interestRate to be a double variable. char a;//Declare a to be a character variable

32 If the variables are of the same type, they can be declared together, separated by commas: datatype variable1, variable2,…variableN; Example: Note that variable names are in lowercase. If a name consists of several words, concatenate all of them and capitalize the first letter of each word except the first. For example: interestRate Cont. Variables 32 int i, j, k;//Declare i, j, k as integer variables

33 A constant is a value that never changes. To create a constant, type the const keyword to its left. When declaring a constant, you must initialize it with an appropriate value. The syntax for declaring a constant: const datatype CONSTANTNAME = VALUE; Example: const double PI = 3.142; Constant 33

34 By convention, constants are named in uppercase. E.g. PI, Not pi or Pi Benefits of using constants: Do not have to repeatedly type the same value. The value can be changed in a single location if necessary. A descriptive name for a constant makes the program easy to read. Constant value cannot be accidentally reassign. Cont. Constants 34

35 Select descriptive names with straightforward meanings for variables, constants, classes and methods. Names are case-sensitive. Use lowercase for variables and methods. If a name consists of several words, concatenate them into one, making the first word lowercase and capitalizing the first letter of each subsequent word. Naming Conventions 35

36 Capitalize the first letter of each word in a classname. E.g. the class names ComputeArea, Math and HelloWorld. Capitalize every letter in a constant, and use underscores between words. E.g. the constants PI and MAX_VALUE. Cont. Naming Conventions 36

37 Contact For Tutorial and Notes Cikguhadi.com Suhardi.suhaimi@pb.edu.bn Digital Media Department Politeknik Brunei Welcome to WADT


Download ppt "C# Web Application and Development Digital Media Department Unit Credit Value : 4 Essential Learning time : 120 hours Digital."

Similar presentations


Ads by Google