1 / 29

CSCI 3328 Object Oriented Programming in C# Chapter 1: Introduction to C#

Learn the fundamentals of object-oriented programming in C# with a focus on the .Net Framework. Understand computer system components, programming evolution, and object technology principles. Hands-on programming practice and guidelines for successful course completion.

eddier
Download Presentation

CSCI 3328 Object Oriented Programming in C# Chapter 1: Introduction to C#

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 3328 Object Oriented Programming in C# Chapter 1: Introduction to C# Xiang Lian The University of Texas – Pan American Edinburg, TX 78539 lianx@utpa.edu

  2. Objectives • In this chapter, you will • Know requirements of this course • Recall basic components in a computer system • Learn the evolution of programming language • Refresh your memory about the object-oriented programming • Become aware of the .Net Framework for Visual C#

  3. Background Required • C++ Programming • If you made an A in 1370/1170 you will do fine with some effort • If you have already taken 2380, you will find this course not very difficult • You need to be able to look up how to get things done (for example, look up syntax)

  4. Programming, Programming, Programming • This class is unlike other courses in that you will spend a lot of time doing actual programming • You should never copy a program from someone else • Even if your program does not perform as good as someone else’s, you should submit what you have • You should not hesitate to ask questions in class

  5. Assignments • Unless I announce it, programs are due in one week after assignment is given in class, or posted • Occasionally, I will give two weeks for difficult programs • You should work on a program the same day it is assigned • That way you can ask questions during the following class period

  6. Use of the Textbook • I will not be covering chapter by chapter • I will cover important points needed to complete the assignments • You need to search the index in the back to find the topic needed for each assignment • You can also obtain help from MSDN at the Microsoft site

  7. Versions of C# • You can program using 2008 or 2010 • Our book only covers 2008 • Usually it takes a year or so for new books to come out • If you use 2010, you have to find help from other sources or the Web

  8. The Time for Class • I expect to hold the class for little over an hour each time • Remaining time should be spend with your assigned groups to discuss the project in class • Please do not exchange programs with each other, just ideas

  9. CSCI 1380: Elements of a Computer System • Hardware • CPU • Main memory • Secondary storage • Input / Output devices • Software • System programs • Application programs (e.g. Visual Studio)

  10. Programming Languages • Machine language • Assembly language • High-level language • E.g., C#

  11. Object Technology • We humans are very good in recognizing and working with objects, such as a pen, a dog, or a human being • We learned to categorize them in such a way that make sense to us. • We may categorize them as animate object, inanimate objects, pets, friends, etc.

  12. Object Technology (cont'd) • We some times classify objects based on their attributes, for example, green apples or red apples, fat or slim people, etc. • If you think about it each object has many attributes. • If I ask you list the attributes of an orange, you probably could list many things such as color, shape, weight, smell, etc.

  13. Object Technology (cont'd) • In addition to attributes, all objects exhibit behaviors. • A dog eats, barks, wags its tail, plays, and begs. • A dog exhibits many more other behaviors than this short list. • Another thing we need to remember about objects is that objects interact between each other

  14. Object Technology in Visual C# • Visual C# • Object-oriented • E.g. forms, labels, buttons, radios, checkboxes, etc. • Properties of objects • E.g. background color of forms • Event-driven • Behaviors  events of objects • E.g. clicks

  15. .Net Framework • A software platform • Language-neutral • Designed for cross-language compatibility • Applications written in C# may reference a DLL file written in any other language • 2 components: • Common Language Runtime (CLR) • Class Libraries

  16. The .Net Framework • Underneath the applications you develop using C# is the .Net Framework containing a library of classes needed for windows forms and web forms. • The .Net framework interacts with the Common Language Runtime (CLR), which in turn interacts with the operating system and the hardware • This way programs you write using C# can run on different operating systems and hardware platforms as long as it has the correct version of the .Net installed on it

  17. Common Language Runtime • Execution Engine of .Net • Manages the execution of programs and provides core services: • Code compilation • Memory allocation • Thread management • Garbage collection

  18. Class Libraries • Designed to integrate with the common language runtime • This library gives the program access to runtime environment • The class library consists of lots of prewritten code that all the applications created in VC# .Net and Visual Studio .Net will use • The code in Visual C # for all the elements like forms, and controls actually comes from the class library

  19. Namespaces • Within the .Net Framework, related classes are grouped into Namespaces • You need to insert a “using AppropriateNamespace” in your program • After that you can refer to methods and attributes of classes contained therein

  20. To Get .Net Namespace Documentation • Visit: http://msdn.microsoft.com/en-us/library/ms229335.aspx

  21. How Do You Write and Run a Program? • Use the Visual Studio to create a project • File New  Project… • The project file will have the extension *.csproj. The project stores all related files, including the source file you write. Every project has a solution file with the extension *.sln. You would be opening this file when you want to return to your program you were writing. This will open all associated files. The associated files may be contained in a subdirectory. • After writing the source code, go to Build and build your solution, which creates the intermediate code • Go to Debug and start without debugging • The program run will finish and give you a prompt to press any key to continue. Starting with debugging, it will complete the run and return to you to the IDE. If your IDE does offer “without debugging”, add a Console.ReadKey() statement.

  22. Options for a New Project • Console application • Windows forms application • …

  23. Hello Program using System; //using System.Collections.Generic; //using System.Linq; //using System.Text; namespace sayHello { class sayHello { static void Main(string[] args) { Console.WriteLine("Hello!"); Console.WriteLine("Welcome to Dr. Lian's C# Class!"); Console.ReadLine(); } } }

  24. Using the Form Designer • You can size the form by holding the handles in the corners or the middle • Controls and other items are added to the form using the toolbox • The control or item has properties that can be set • To write the code for an event, you can click on the view code button above the solution explorer or by simply clicking on a button or anything else on the form • Files with code you write will have extension .cs • Files ending with designer.cs are code files generated by Visual Studio

  25. Naming Controls and Boxes • Use a convention you will remember • You can start all button names with btn • An accept button will be named btnAccept • An exit button will be named btnExit • All text boxes will start with txt • Sales amount will be named txtSalesAmount • All labels with start with lbl • lblEnterName • It is up to you to choose naming conventions you will recognize

  26. Your First Assignment • Assignment #1 • The purpose of this assignment is to practice reading and writing to console using C#. It is a simple assignment. Use the following program run to design and write your program. Please submit Program listing and a screen capture of the program run. Follow the textbook examples to add comments as documentation.

  27. Assignment Submission • Make sure to include your name, assignment number, date due and date completed on each assignment you submit • Assignment should be submitted in a manila folder with your name and assignment number appearing on the tab • Submit your assignments to the Blackboard

  28. Exercises • Give a brief explanation of the .NET framework • What is the Common Language Runtime? • How do you place “Total Square Feet: 1238” in a text box? Assume that 1238 in an integer stored in a variable called sqFt.

More Related