Presentation is loading. Please wait.

Presentation is loading. Please wait.

Windows Programming 1 Part 1 dbg --- Getting Acquainted with Visual Studio.NET and C#

Similar presentations


Presentation on theme: "Windows Programming 1 Part 1 dbg --- Getting Acquainted with Visual Studio.NET and C#"— Presentation transcript:

1 Windows Programming 1 Part 1 dbg --- Getting Acquainted with Visual Studio.NET and C#

2 2 The Visual Studio.NET IDE Visual Studio.NET is an Integrated Development Environment (IDE). It contains: –the Designer which makes it easy to create Graphical User Interfaces (GUIs) –a context-sensitive text editor –various language compilers (we will be using C#) –a runtime environment for testing/debugging our code Visual Studio.NET can be used with other programming languages such as C++ and Visual Basic

3 3 Programming Windows with.NET.NET is a “programming platform” for Windows. An important feature is that applications are especially “tuned” for network use. Another interesting feature is that the platform allows applications written with several different languages to directly communicate with each other.

4 4 The.NET Framework Common Language Specification ASP.NET: Web Services and Web Forms Windows Forms ADO.NET: Data and XML Framework Class Library Common Language Runtime VB C++ C# J# … Visual Studio.NET

5 Procedural programming + classes Where Does C# Fit? 1967 1970 1972 1985 1998 2000 BCPL B C C++ C++ C++.NET 1997 2000 BASIC Visual BASIC BASIC.NET MS Visual 1965 1991 2000 C# combines the best features of C/C++, Java, and VB in a new visual, fully object-oriented, event- driven programming language designed for use with the.NET platform. Procedural programming + classes MS 1995 2000 Sun Microsystems Java GUIs Web Programming Fully OOP ANSI/ISO MS Visual C#.NET

6 6 Programming Windows with C# A new language designed specifically for.NET Fully object-oriented Type safe language Built-in Visual Editor for GUI development Fundamental programming syntax resembles that of C++ and Java

7 7 Importance of C# Microsoft wrote much of.NET system programming in C# and is currently writing next version of Windows (Longhorn) in C#. In “Special Report: Security”, PC Magazine, pg 78, 8/3/04 issue: “ ‘In the course of putting together Longhorn,’ says Nash, [of Microsoft] ‘… we’re making sure that in the design phase, the implementation phase, as we build the product, we’re looking for security and quality issues.’ The company is also using design tools that are far more conducive to building secure code. It has discarded notoriously insecure languages like C and C++ in favor of C# and the Microsoft.NET platform.”

8 8 C# Features A considerable amount of pre-defined code resides in the Framework Class Library (FCL). C# can be used to develop –Console applications (procedural programming) –Interactive Windows Forms applications (GUIs) –Web Services (server programs) –Interactive Web Forms (via ASP.NET) Like other.NET languages, code is compiled first into MSIL (MS Intermediary Language) and then into machine language.

9 Objects Getting Started with Object Oriented Programming

10 10 Objects (nouns) An object is a person, place or thing. In theory, we should be able to describe all of our experience and surroundings as objects. All objects have attributes and operations.

11 11 Attributes (adjectives) Attributes are characteristics. Use attributes to describe the appearance of an object. Size, shape and color could be attributes of many objects. A football is brown in color and roughly oval in shape; these characteristics represent values assigned to attributes.

12 12 Operations (verbs) Operations are actions. User operations to describe the “active” behavior of an object. A football might, spiral, tumble, roll or bounce. These behaviors become evident if a specific operation of the object is activated.

13 13 Classes (templates) Classes are patterns for objects. You might think of a class as a cookie cutter and a set of objects as cookies created with that cutter (class). An object is an instance of a class, and the process of creating an object is called instantiation. Class Objects

14 14 Classes In practice, a class is a unit or module of code that may be used to define the attributes and operations of an object. Some classes will exist within the Windows applications we will write. Other classes pre-exist and are stored in special files called libraries.

15 15 Data and Actions Within a class, attributes are represented by variables. After an object is created from a class, values may be assigned to these variables to adjust attributes. Within a class, operations are represented by methods. After an object is created from a class, an operation may be triggered by running a method.

16 16 Encapsulation It is not necessary for a programmer who uses a pre-existing class to know or understand its code structure. This concept is called encapsulation; its implications are significant.

17 17 A Class Interface The implementation code of a class is encapsulated (hidden from view). Properties define the characteristics (data) of an object. Methods are operations that an object can perform. Properties and methods can be referred to as members of an object/class.

18 18 Visual Studio Icons PropertyNamespace EventClass MethodConstant

19 19 Syntax for Using Properties and Methods Programmers use dot notation to gain access to properties and methods. To assign a value to a property of an object: object. property = value To run a method (function) of an object: object. method Remember: methods (functions) always have parentheses!

20 C# Programming A Simple Windows Application Programmed with C#

21 21 Create Objects with the FCL At this point, we know nothing of the structure of the classes in the Framework Class Library. If we know the identity of just some of the attributes (properties) and operations (methods) we wish to use, we should be able to create and manipulate an object.

22 22 Namespaces Large libraries of classes are arranged into sub libraries of related classes. These sub libraries are called namespaces..NET programs are organized into projects, where each project normally comprises a namespace.

23 23 Inheriting a Class from the FCL Sometimes an existing class does almost, or nearly what we want. We can create our own class and inherit the contents of the original class.

24 24 Running a Method The Main() method indicates which object runs automatically at startup time. In.NET 2005, the Main() method will reside in a file named Program.cs. In this example, our form class is the startup object. We are activating the Run() method of the Application object from the System.Windows.Forms namespace.

25 25 Running a Method The Run() method within the Application class requires an argument or parameter. We pass the keyword new and the name of our form class as the function argument. Main() is always capitalized!

26 26 Assigning a Property Value Our form has a Text property. The value stored in the Text property of a Form will appear in the title bar of the form.

27 27 Assigning a Property Value Any property value assignments must be made within functions. We are making our text property assignment within a special function called the constructor.

28 28 The Constructor Function In C#, the constructor function has the same name as the class itself. The constructor may have optional arguments (parameters), if desired. The constructor runs at the instant an object is created from a class — instantiation. Code in the constructor function can set the initial values of variables and properties. An object of our class is instantiated at startup of the project.


Download ppt "Windows Programming 1 Part 1 dbg --- Getting Acquainted with Visual Studio.NET and C#"

Similar presentations


Ads by Google