Lecture notes for .net framework

asp.net framework advantages and asp net framework and components pdf free download
LottieBarners Profile Pic
LottieBarners,Hawaii,Researcher
Published Date:12-07-2017
Your Website URL(Optional)
Comment
Chapter 1 Introduction to .NET 1.0 Objectives 1.1 Introduction 1.2 .NET Framework 1.2.1 Net Framework and .Net Languages 1.2.2 Languages supported by .Net Framework 1.3 .NET Class Library 1.4 ASP vs. ASP.NET 1.5 Summary 1.6 Check your Progress - Answers 1.7 Questions for Self – Study 1.8 Suggested Readings 1.0 OBJECTIVES After studying this chapter you will be able to –  explain .NET Framework.  describe the .Net languages.  explain the .Net class library.  explain difference between ASP and ASP.NET. 1.1 INTRODUCTION Microsoft .NET technology you will have access to a new generation of advanced software joining the best of computing and communications in a revolutionary new way. The effect will be to totally transform the Web and every other aspect of the computing experience. .NET enables developers, businesses, and consumers to harness technology on their terms. .NET will allow the creation of truly distributed Web services that will integrate and collaborate with a range of complementary services to help customers in ways that today’s dotcoms can only dream of. The fundamental idea behind .NET is that the focus is shifting from individual Web sites or devices connected to the Internet to constellations of computers, devices, and services that work together to deliver broader, richer solutions. People will have control over how, when, and what information is delivered to them. Computers, devices and services will be able to collaborate with each other to provide rich services, instead of being isolated islands where the user provides the only integration. Businesses will be able to offer their products and services in a way that lets customers seamlessly embed them in their own electronic fabric. Microsoft .NET will make computing and communicating simpler and easier than ever. It will spawn a new generation of Internet services, and enable tens of thousands of software developers to create revolutionary online services and businesses. It will put you back in control, and enable greater control of your privacy, digital identity, and data. And software is what makes it all possible. However, Microsoft’s .NET technology will only succeed if others adopt this new standard. Source: http://vig.prenhall.com/samplechapter/013093285X.pdf 1.2 .NET FRAMEWORK The Microsoft .NET Framework is a software compatible work that is available with several Microsoft Windows operating systems. It includes a large library of pre- coded solutions to common programming problems and a virtual machine that Introduction to .NET / 1 manages the execution of programs written specifically for the framework. The .NET Framework is a key Microsoft offering and is intended to be used by most new applications created for the Windows platform. The pre-coded solutions that form the framework's Base Class Library cover a large range of programming needs in a number of areas, including user interface, data access, database connectivity, cryptography, web application development, numeric algorithms, and network communications. The class library is used by programmers, who combine it with their own code to produce applications. Programs written for the .NET Framework execute in a software environment that manages the program's runtime requirements. Also part of the .NET Framework, this runtime environment is known as the Common Language Runtime (CLR). The CLR provides the appearance of an application virtual machine so that programmers need not consider the capabilities of the specific CPU that will execute the program. The CLR also provides other important services such as security, memory management, and exception handling. Source: https://sites.google.com/site/entirefacts/dotnet Version 3.0 of the .NET Framework is included with Windows Server 2008 and Windows Vista. The current version of the framework can also be installed on Windows XP and the Windows Server 2003 family of operating systems. A reduced "Compact" version of the .NET Framework is also available on Windows Mobile platforms, including smart phones. NET Framework Advantages of .NET The .NET Framework provides the following advantages:  A consistent, object-oriented programming environment.  A code-execution environment that: o Promotes safe execution of code. ASP .NET / 2 o Eliminates the performance problems of scripted or interpreted environments. o Minimizes software deployment and versioning conflicts.  A consistent experience for both developers and users across various types of Windows-based and Web-based applications on multiple devices.  Communication built on the industry standards to ensure that code based on the .NET Framework can integrate with any other code. .NET is based on open Internet standards, which include Hypertext Transfer Protocol (HTTP), Extensible Markup Language (XML), and Simple Object Access Protocol (SOAP). 1.2.1 .NET Framework and .NET Languages As mentioned on the .NET Framework page, .NET Framework is designed for cross-language compatibility. Cross-language compatibility means .NET components can interact with each other irrespective of the languages they are written in. An application written in VB .NET can reference a DLL file written in C or a C application can refer to a resource written in VC++, etc. This language interoperability extends to Object-Oriented inheritance. This cross-language compatibility is possible due to common language runtime. As you read on the .NET Framework page, when the .NET program is compiled, the output of the compiler is not an executable file but a file that contains a special type of code called the Microsoft Intermediate Language (MSIL). This MSIL is a low-level language which is designed to be read and understood by the common language runtime. Because all .NET executables exist as IL, they can freely operate. The Common Language Specification defines the minimum standards that .NET language compliers must confirm to. Thus, any code compiled by a .NET complier can interoperate with the .NET Framework. The Common Type System (CTS) defines the rules concerning data types and ensures that code is executed in a safe environment. Since all .NET applications are converted to IL before execution all primitive data types are represented as .NET types. This means that, a VB Integer and a C integer are both represented in IL code as System.Int32. Because both the languages use a common type system, it is possible to transfer data between components and avoid time-consuming conversions. 1.2.2 Languages supported by .NET Framework The table below lists all the languages supported by the .NET Framework and describes those languages. Language Description/ Usage APL (A Programming Language) is one of the most APL powerful, consistent and concise computer programming languages ever devised. It is a language for describing procedures in the processing of information. It can be used to describe mathematical procedures having nothing to do with computers or to describe the way a computer works. C++ is a true OOP. It is one of the early Object-Oriented C++ programming languages. C++ derives from the C language. Visual C++ is the name of a C++ compiler with an integrated environment from Microsoft. This includes special tools that simplify the development of great applications, as well as specific libraries. Its use is known as visual programming. C called as C Sharp is a fully fledged Object-Oriented C programming language from Microsoft built into the .NET Framework. First created in the late 1990’s was part of Microsoft’s whole .NET strategy. COBOL (Common Business Oriented Language) was Cobol the first widely-used high-level programming language for business applications. It is considered as a Introduction to .NET / 3 programming language to have more lines of code than any other language. Eiffel is an Object-Oriented (OO) programming Eiffel language which emphasizes the production of robust software. Eiffel is strongly statically typed mature Object-Oriented language with automatic memory management. Formula Translator, Fortran is one of the oldest high- Fortran level programming languages that are still widely used in scientific computing because of its compact notation for equations, ease in handling large arrays, and huge selection of library routines for solving mathematical problems efficiently. Haskell is a computer programming language that is a Haskell polymorphic typed, lazy, purely functional language, quite different from most other programming languages. It is a wide-spectrum language, suitable for a variety of applications. It is particularly suitable for programs which need to be highly modifiable and maintainable. The Java language is one of the most powerful Object- Java Oriented programming languages developed till date. Its Language platform independence (not depending on a particular OS) feature makes it a very popular programming language. Microsoft JScript is the Microsoft implementation of the Microsoft ECMA 262 language specification. JScript is an JScript interpreter, object-based scripting language. It has fewer capabilities than full-fledged Object-Oriented languages like C++ but is more than sufficiently powerful for its intended purposes. Mercury is a new logic/functional programming Mercury language, which combines the clarity and expressiveness of declarative programming with advanced static analysis and error detection features. Its highly optimized execution algorithm delivers efficiency far in excess of existing logic programming systems, and close to conventional programming systems. Mercury addresses the problems of large- scale program development, allowing modularity, separate compilation, and numerous optimization/time trades-offs. Mondrian is a simple functional scripting language for Mondrian Internet applications. It is a functional language specifically designed to inter-operate with other languages in an OO environment. Current versions of Mondrian run on .NET. Mondrian also supports ASP.NET, allowing you to embed functional language code in web pages along with C code. Oberon is a programming language very much like Oberon Modula-2 in syntax but with several interesting features. It's based on OOP concepts and provides a Windows- based graphical user interface. Oz is a high-level programming language that combines Oz constraint inference with concurrency. Oz is dynamically typed and has first-class procedures, classes, objects, exceptions and sequential threads synchronizing over a constraint store. It supports finite domain and feature constraints and has powerful primitives for programming constraint inference engines at a high level. ASP .NET / 4 Practical Extraction and Report Language, Perl, is a Perl language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It's also a good language for many system management tasks. Python is an interpreter, interactive, Object-Oriented Python programming language. Python combines remarkable power with very clear syntax. It has modules, classes, exceptions, very high level dynamic data types, and dynamic typing. Report Program Generator, RPG, is used for generation RPG of reports from data files, including matching record and sub-total reports. RPG is one of the few languages created for punch card machines that are still in common use today. RPG or RPG IV is a native programming language for IBM's iSeries minicomputer system. Scheme is a statically scoped programming language. It Scheme was designed to have an exceptionally clear and simple semantics and few different ways to form expressions. A wide variety of programming paradigms, including imperative, functional, and message passing styles, find convenient expression in Scheme. Small Talk is an expressive language that uses a simple Small Talk sub set of human languages, nouns and verbs. Smalltalk was the first, and remains one of the few; pure object a system, which simply means that everything in a Smalltalk program is an object. Smalltalk is generally recognized as the second Object Programming Language (OPL). Standard ML is a safe, modular, strict, functional, Standard ML polymorphic programming language with compile-time type checking and type inference, garbage collection, exception handling, immutable data types and updatable references, abstract data types, and parametric modules. It has efficient implementations and a formal definition with a proof of soundness. Visual Basic is a "visual programming" environment for Microsoft developing Windows applications. Visual Basic makes it Visual Basic possible to develop complicated applications very quickly. This site is all about Visual Basic. 1.3 .NET CLASS LIBRARY The .NET Framework class library is a library of classes, interfaces, and value types that are included in the Windows Software Development Kit (SDK). This library provides access to system functionality and is designed to be the foundation on which .NET Framework applications, components, and controls are built. Namespaces: Namespace Description System The System namespace contains fundamental classes and base classes that define commonly-used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions. System.Data The System.Data namespaces contain classes for accessing and managing data from diverse sources. The top-level namespace and a number of the child namespaces together form the ADO.NET architecture and ADO.NET data providers. For example, providers are available for SQL Server, Oracle, ODBC, and OleDB. Introduction to .NET / 5 Other child namespaces contain classes used by the ADO.NET Entity Data Model (EDM) and by WCF Data Services. System.IO The System.IO namespaces contain types that support input and output, including the ability to read and write data to streams either synchronously or asynchronously, to compress data in streams, to create and use isolated stores, to map files to an application's logical address space, to store multiple data objects in a single container, to communicate using anonymous or named pipes, to implement custom logging, and to handle the flow of data to and from serial ports. System.Net The System.Net namespaces contain classes that provide a simple programming interface for a number of network protocols, programmatically access and update configuration settings for the System.Net namespaces, define cache policies for web resources, compose and send e-mail, represent Multipurpose Internet Mail Exchange (MIME) headers, access network traffic data and network address information, and access peer-to- peer networking functionality. Additional child namespaces provide a managed implementation of the Windows Sockets (Winsock) interface and provide access to network streams for secure communications between hosts. System.Web The System.Web namespaces contain types that enable browser/server communication. Child namespaces include types that support ASP.NET forms authentication, application services, data caching on the server, ASP.NET application configuration, dynamic data, HTTP handlers, JSON serialization, incorporating AJAX functionality into ASP.NET, ASP.NET security, and web services. System.Windows The System.Windows namespaces contain types used in Windows Presentation Foundation (WPF) applications, including animation clients, user interface controls, data binding, and type conversion. System.Windows.Forms and its child namespaces are used for developing Windows Forms applications. Source : from Microsoft MSDN 1.4 ASP VS. ASP.NET ASP: 1) ASP is run under the inetinfo.exe (IIS) process space and hence susceptible to application crashes as a result the IIS needs to be stopped or restarted. ASP is related to the process isolation setting in IIS. 2) Classical ASP had no mechanism of running itself on non- Microsoft technology platforms like the 'The Apache Web Server' 3) In ASP only two languages were available for scripting VBScript and Jscript/JavaScript. 4) In ASP, ASP engine executes server-side code, which is always through an interpreter (JScript or VBScript). When a traditional ASP page is requested, the text of that page is parsed linearly. All content that is not server-side script is rendered as is back to the response. All server-side script in the page is first run through the appropriate interpreter (JScript or VBScript), the output of which is ASP .NET / 6 then rendered back to the response. This architecture affects the efficiency of page rendering in several ways. Thus, to improve efficiency of rendering, many ASP developers resort to large blocks of server-side script, replacing static HTML elements with Response.Write() invocations instead. Finally, this ASP model actually allows different blocks of script within a page to be written in different script languages. 5) In classic ASP it was very difficult for us to debug the application. ASP developers had time to debug application due to limited support due to the interpreted model. 6) Class=docTextespecially if you are using ASP pages it is possible to include executable code outside the scope of a function within a script block marked as runat=server, and, it is possible to define a function within a pair of server-side script tags. 7) New Page Directives: In ASP you must place all directives on the first line of a page within the same delimiting block. For example: %LANGUAGE="VBSCRIPT" CODEPAGE="932"% ASP.NET 1) The ASP.NET worker process is a distinct worker process, aspnet_wp.exe, separate from inetinfo.exe (IIS process), and the process model in ASP.NET is unrelated to process isolation settings in IIS. 2) ASP.NET could be run on non-Microsoft Platforms also. 3) We are no longer constrained to the two scripting languages available in traditional ASP: Any fully compliant .NET language can now be used with ASP.NET, including C and VB.NET. 4) In contrast, ASP.NET pages are always compiled into .NET classes housed within assemblies. This class includes all of the server-side code and the static HTML, so once a page is accessed for the first time (or any page within a particular directory is accessed), subsequent rendering of that page is serviced by executing compiled code. This eliminates all the inefficiencies of the scripting model of traditional ASP. There is no longer any performance difference between compiled components and server-side code embedded within a page they are now both compiled components. There is also no performance difference between interspersing server-side code blocks among static HTML elements, and writing large blocks of server-side code and using Response .Write() for static HTML content. Also, because the .aspx file is parsed into a single code file and compiled, it is not possible to use multiple server-side languages within a single .aspx file. 5) But in ASP.NET In addition to improved performance over the interpreted model, pages that are compiled into classes can be debugged using the same debugging tools available to desktop applications or component developers. Errors with pages are generated as compiler errors, and there is a good chance that most errors will be found at compilation time instead of runtime, because VB.NET and C are both strongly typed languages. Plus, all the tools available to the .NET developer are applicable to the .aspx developer. 6) In ASP.NET it is no longer possible to include executable code outside the scope of a function within a script block marked as runat=server, and conversely, it is no longer possible to define a function within a pair of server-side script tags. 7) But in ASP.NET, you are now required to place the Language directive with a Page directive, as follows: %Page Language="VB" Code Page="932"% %Output Cache Duration="60" Vary By Param="none" % You can have as many lines of directives as you need. Directives may be located anywhere in your .apsx file but standard practice is to place them at the beginning of the file. Several new directives have been added in ASP.NET. Introduction to .NET / 7 1.5 SUMMARY  The fundamental idea behind .NET is that the focus is shifting from individual Web sites or devices connected to the Internet to constellations of computers, devices, and services that work together to deliver broader, richer solutions.  The .NET Framework is a key Microsoft offering and is intended to be used by most new applications created for the Windows platform.  .NET Framework is designed for cross-language compatibility. Cross-language compatibility means .NET components can interact with each other irrespective of the languages they are written in.  All the languages supported by the .NET Framework is C++, C, COBOL, Eiffel, Java, Perl etc. Check your Progress – 1.2-1.4 True or False a. .Net Frame work is a software compatible work that is available with several Microsoft windows operating system. b. CLS defines rules concerning data types. c. C++ language is supported by .NET framework. d. MSIL is a low-level language. e. ASP.NET could not run on non-Microsoft Platforms. 1.6 CHECK YOUR PROGRESS – ANSWERS a. True b. False c. True d. True e. False 1.7 QUESTIONS FOR SELF - STUDY a) Explain brief introduction to .NET. b) Explain languages supported by .Net Frame work. c) Explain .NET framework with diagram. d) What is the difference between ASP and ASP.NET? 1.8 SUGGESTED READINGS 1. Microsoft MSDN 2. http://vig.prenhall.com/samplechapter/013093285X.pdf 3. Source: http://devreminder.wordpress.com/net/net-framework-fundamentals/ 4. https://sites.google.com/site/entirefacts/dotnet 5. http://en.wikipedia.org/wiki/.NET_Framework_version_history  ASP .NET / 8 NOTES Introduction to .NET / 9 NOTES ASP .NET / 10 Chapter 2 C Fundamentals 2.0 Objectives 2.1 Introduction 2.2 Writing Simple C Program 2.3 Flow control 2.3.1 The if Statement 2.3.2 The Switch Statement 2.4 Boolean logic 2.5 The goto statement 2.6 Branching 2.7 Looping 2.7.1 Do Statement 2.7.2 For Statement 2.7.3 For Reach Statement 2.7.4 While Statement 2.8 OOP in C 2.8.1 Constructors & Overloading 2.8.2 Namespace & Class Library 2.9 Inheritance 2.10 Summary 2.11 Check your Progr ess - Answers 2.12 Questions for Self – Study 2.13 Suggested Readings 2.0 OBJECTIVES After studying this chapter you will be able to –  Explain simple C program.  explain the flow control from C  explain the various statements like goto, branching, and looping  explain OOP in C 2.1 INTRODUCTION Microsoft has also developed a brand new programming language C (C Sharp). This language makes full use of .NET. It is a pure object oriented language. C is a simple, modern object oriented and type-safe programming language derived from C and C++. It will immediately be familiar to C and C++ programmers. C aims to combine the high productivity of visual basic and the raw power of C++. Visual C .NET is Microsoft’s C development tool. It includes an interactive development environment, visual designers for building windows and web applications, a compiler, and a debugger. Visual C .NET is part of a suite of products; call Visual Studio .NET, which also included Visual Basic .NET, Visual C++ .NET, and the Jscript scripting language. All of these languages provide access to the Microsoft .NET Framework, which includes a common execution engine and a rich class library. C Fundamentals / 11 The modern design of C eliminates the most common C++ programming errors. C empowers the traditional C/C++ programmer by providing:  Automated garbage collection that relieves the programmer of the burden of manual memory management  Automatically initialized variables  Type-safe variables C is a language that makes it far easier for developers to create and maintain applications that solve complex business problems. 2.2 WRITING SIMPLE C PROGRAM We'll now write the "Hello, world" example application to get to know the basic syntax and structure of writing C applications. Program Hello.cs using System; class Hello public static void Main(string args) Console.WriteLine("Hello, world"); The default file extension for C programs is .cs, as in hello.cs. The name of the program can be hello.cs or any name you want. OUTPUT: Hello, world Detailed description of this program is:  The using System; directive references a namespace called System that is provided by the Microsoft .NET Framework class library. This namespace contains the Console class referred to in the Main method. Namespaces provide a hierarchical means of organizing the elements of one or more programs. A “using” directive enables unqualified use of the types that are members of the namespace. The “hello, world” program uses Console.WriteLine as shorthand for System.Console.WriteLine.  The Main method is a member of the class Hello. It has the static modifier, and so it is a method on the class Hello rather than on instances of this class.  The entry point for an application—the method that is called to begin execution—is always a static method named Main.  The “hello, world” output is produced using a class library. The language does not itself provide a class library. Instead, it uses a class library that is also used by Visual Basic .NET and Visual C++ .NET. Source : http://msdn.microsoft.com/en-IN/library/aa664628(v=vs.71).aspx 2.3 FLOW CONTROL This section looks at the real nuts and bolts of the language: the statements that allow you to control the flow of your program rather than executing every line of code in the order it appears in the program. Conditional Statements: Conditional statements allow you to branch your code depending on whether certain conditions are met or on the value of an expression. C has two constructs for branching code –if statement, which allows you to test whether a specific condition is met, and the switch statement, which allows you to compare an expression with a number of different values. ASP .NET / 12 2.3.1 The if statement The, if statement selects a statement for execution based on the value of a Boolean expression. Example: This example checks if the input character is lowercase, uppercase, or a number. Otherwise, it is not an alphanumeric character. The program makes use of the else-if ladder. // statements_if_else2.cs // else-if using System; public class IfTest static void Main (String()arys) Console.Write("Enter a character: "); char c = (char)Console.Read(); if (Char.IsUpper(c)) Console.WriteLine("Character is uppercase."); else if (Char.IsLower(c)) Console.WriteLine("Character is lowercase."); else if (Char.IsDigit(c)) Console.WriteLine("Character is a number."); else Console.WriteLine("Character is not alphanumeric."); Input ABC Output Enter a character: ABC The character is uppercase. C Fundamentals / 13 2.3.2 The Switch Statement The switch statement is a control statement that handles multiple selections and enumerations by passing control to one of the case statements within its body as the following example: // statements_switch.cs using System; class SwitchTest static void Main() Console.WriteLine("Coffee sizes: 1=Small 2=Medium 3=Large"); Console.Write("Please enter your selection: "); string s = Console.ReadLine(); int n = int.Parse(s); int cost = 0; switch(n) case 1: cost += 25; break; case 2: cost += 25; goto case 1; case 3: cost += 50; goto case 1; default: Console.WriteLine("Invalid selection. Please select 1, 2, or 3."); break; if (cost = 0) Console.WriteLine("Please insert 0 cents.", cost); Console.WriteLine("Thank you for your business."); Input 2 Sample Output Coffee sizes: 1=Small 2=Medium 3=Large Please enter your selection: 2 Please insert 50 cents. Thank you for your business. Example 2: // statements_switch2.cs using System; class SwitchTest static void Main() int n = 2; switch(n) case 1: case 2: case 3: Console.WriteLine("It's 1, 2, or 3."); break; default: Console.WriteLine("Not sure what it is."); break; ASP .NET / 14 Output Its 1, 2 or 3 Check your progress. 2.3 Answer the following questions in 1-2 sentences. a) What is C? ………………………………………………………………………..………………………... ………………………………………………………………………..………………………... b) What is flow control? ………………………………………………………………………..………………………... ………………………………………………………………………..………………………... 2.4 BOOLEAN LOGIC The bool type represents Boolean logical quantities. The possible values of type bool are true and false. No standard conversions exist between bool and other types. In particular, the bool type is distinct and separate from the integral types, and a bool value cannot be used in place of an integral value, and vice versa. In the C and C++ languages, a zero integral value or a null pointer can be converted to the Boolean value false, and a non-zero integral value or a non-null pointer can be converted to the Boolean value true. In C, such conversions are accomplished by explicitly comparing an integral value to zero or explicitly comparing an object reference to null. C++ has a separate Boolean data type ('bool'), but with automatic conversions from scalar and pointer values that are very similar to those of C. This approach was adopted also by many later languages, especially by some scripting ones such as AWK. One problem with this approach is that the tests if(t==TRUE)... and if(t) are not equivalent. Boolean type; a bool value is either true or false bool val1 = true; bool val2 = false; Examples: using System; class Test static void Main() string s = "Test"; string t = string.Copy(s); Console.WriteLine(s == t); Console.WriteLine((object)s == (object)t); Sample Output True False C Fundamentals / 15 2.5 THE GOTO STATEMENT The goto statement transfers the program control directly to a labeled statement. A common use of goto is to transfer control to a specific switch-case label or the default label in a switch statement. The goto statement is also useful to get out of deeply nested loops. Example: // statements_goto_switch.cs using System; class SwitchTest static void Main() Console.WriteLine("Coffee sizes: 1=Small 2=Medium 3=Large"); Console.Write("Please enter your selection: "); string s = Console.ReadLine(); int n = int.Parse(s); int cost = 0; switch (n) case 1: cost += 25; break; case 2: cost += 25; goto case 1; case 3: cost += 50; goto case 1; default: Console.WriteLine("Invalid selection."); break; if (cost = 0) Console.WriteLine("Please insert 0 cents.", cost); Console.WriteLine("Thank you for your business."); Input 2 Sample Output Coffee sizes: 1=Small 2=Medium 3=Large Please enter your selection: 2 Please insert 50 cents. Thank you for your business. 2.6 BRANCHING Changing the flow of control in a program in response to some kind of input or calculated value is an essential part of a programming language. C provides the ability to change the flow of control, either unconditionally, by jumping to a new location in the code, or conditionally, by performing a test. Example : using System; class Program static void Main() int x = 1; ASP .NET / 16 int y = 1; if (x == 1) Console.WriteLine("x == 1"); else Console.WriteLine("x = 1"); if (x == 1) if (y == 2) Console.WriteLine("x == 1 and y == 2"); else Console.WriteLine("x == 1 and y = 2"); Output: Student should evaluate this program for practice. 2.7 LOOPING You can create loops by using the iteration statements. Iteration statements cause embedded statements to be executed a number of times, subject to the loop- termination criteria. These statements are executed in order, except when a jump statement is encountered. The following keywords are used in iteration statements:  do  for  foreach  while 2.7.1 Do statement The do statement executes a statement or a block of statements enclosed in repeatedly until a specified expression evaluates to false. In the following example the do loop statements execute as long as the variable y is less than 5. The do while construct consists of a process symbol and a condition. First, the code within the block is executed, and then the condition is evaluated. If the condition is true the code within the block is executed again. This repeats until the condition becomes false. Example : // statements_do.cs using System; public class TestDoWhile public static void Main () int x = 0; do Console.WriteLine(x); x++; while (x 5); C Fundamentals / 17 Output 0 1 2 3 4 2.7.2 For Statement For loop executes a statement or a block of statements repeatedly until a specified expression evaluates to false. For loop is handy for iterating over arrays and for sequential processing. In the following example, the value of int i is written to the console and i is incremented each time through the loop by 1. Example : // statements_for.cs // for loop using System; class ForLoopTest static void Main() for (int i = 1; i = 5; i++) Console.WriteLine(i); Output 1 2 3 4 5 2.7.3 Foreach Statement The foreach statement repeats a group of embedded statements for each element in an array or an object collection. The foreach statement is used to iterate through the collection to get the desired information, but should not be used to change the contents of the collection to avoid unpredictable side effects. Example: // cs_foreach.cs class ForEachTest static void Main(string args) int fibarray = new int 0, 1, 2, 3, 5, 8, 13 ; foreach (int i in fibarray) System.Console.WriteLine(i); Output 0 1 2 3 5 8 13 ASP .NET / 18 2.7.4 While Statement The while statement executes a statement or a block of statements until a specified expression evaluates to false. Example: // statements_while.cs using System; class WhileTest static void Main() int n = 1; while (n 6) Console.WriteLine("Current value of n is 0", n); n++; Output Current value of n is 1 Current value of n is 2 Current value of n is 3 Current value of n is 4 Current value of n is 5 Check your progress. 2.7 Answer the following questions in 1-2 sentences. a) What is Boolean logic? ………………………………………………………………………..………………………... ………………………………………………………………………..………………………... b) Explain the goto statement. ………………………………………………………………………..………………………... ………………………………………………………………………..………………………... c) Explain foreach statement. ………………………………………………………………………..………………………... ………………………………………………………………………..………………………... 2.8 OOP IN C What is OOP? Object-oriented programming (OOP) is a programming paradigm that represents concepts as "objects" that have data fields and associated procedures known as methods. Objects, which are usually instances of classes, are used to interact with one another to design applications and computer programs. All code and data in C must be enclosed in a class. You can't define a variable outside of a class, and you can't write any code that's not in a class. Classes can have constructors, which execute when an object of the class is created, and a destructor, which executes when an object of the class is destroyed. Classes support C Fundamentals / 19 single inheritance, and all classes ultimately derive from a base class called object. C supports versioning techniques to help your classes evolve over time while maintaining compatibility with code that uses earlier versions of your classes. As an example, take a look at a class called Family. This class contains the two static fields that hold the first and last name of a family member as well as a method that returns the full name of the family member. class Class1 public string FirstName; public string LastName; public string FullName() return FirstName + LastName; Note Single inheritance means that a C class can inherit from only one base class. C enables you to group your classes into a collection of classes called a namespace. Namespaces have names, and can help organize collections of classes into logical groupings. As you begin to learn C, it becomes apparent that all namespaces relevant to the .NET Framework begin with System. Microsoft has also chosen to include some classes that aid in backwards compatibility and API access. These classes are contained within the Microsoft namespace. The most significant enhancement of the C++ language is its support for object-oriented programming (OOP). You will have to modify your approach to problem solving to derive all of the benefits of C++. For example, objects and their associated operations must be identified and all necessary classes and subclasses must be constructed. 2.8.1 Constructors and overloading Often you'll want to have more than one function with the same name. The most common example of this is to have more than one constructor. In the examples shown so far, the constructor has taken a single parameter: a DateTime object. It would be convenient to be able to set new Time objects to an arbitrary time by passing in year, month, date, hour, minute, and second values. It would be even more convenient if some clients could use one constructor, and other clients could use the other constructor. Function overloading provides for exactly these contingencies. The signature of a method is defined by its name and its parameter list. Two methods differ in their signatures if they have different names or different parameter lists. Parameter lists can differ by having different numbers or types of parameters. For example, in the following code the first method differs from the second in the number of parameters, and the second differs from the third in the types of parameters: Source : Programming C: Building .NET Applications with C By Jesse Liberty void myMethod(int p1); void myMethod(int p1, int p2); void myMethod(int p1, string s1); A class can have any number of methods, as long as each one's signature differs from that of all the others. Example : illustrates our Time class with two constructors, one which takes a DateTime object, and the other which takes six integers. Example : Overloading the constructor public class Time // public accessor methods public void DisplayCurrentTime( ) ASP .NET / 20

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.