560 likes | 602 Views
About C# BY: MARK ANTHONY P. CEZAR. C# C Sharp New Language introduced by Microsoft Goal is to provide ease of working, flexibility, and power of the Java and C++ languages. Fully Object Oriented PL Allows Programmer to develop applications Under windows and web browser.
E N D
About C# BY: MARK ANTHONY P. CEZAR
C# • C Sharp • New Language introduced by Microsoft • Goal is to provide ease of working, flexibility, and power of the Java and C++ languages. • Fully Object Oriented PL • Allows Programmer to develop applications Under windows and web browser
Research History 1 Yellow Pad
Installation .NET Framework v 3.5 Visual Studio Visual C# (2008,2010,2011) MSDN – Microsoft Developers Network(optional)
Terminologies Objects as a thing . Examples of objects are forms and controls Properties tell something about object behavior such as names , color, size or location Methods action associated with objects are called method. Typical methods are Close, Show and Clear.
Events write methods that execute when a particular Events occurs. An event occurs when the user takes an action such as clicking a button. Classes Contain definition of all available properties, Methods and events. It is a template or blueprint used to create a new object.
GOOD PROGRAMMING 3 Steps for Planning and for developing the project. Planning Programming • Design the user interface 1. Define the user interface • Plan the properties 2. Set the Properties • Plan the c# code 3. Write the code
IDE MAIN WINDOW • Visual Studio Environment and its various child window. • IDE main window holds VS menu bar, toolbars, display or hide Windows from the view menu
IDE MAIN WINDOW Consists of: Toolbars each button represents a command that can be selected from a menu. Document Window the largest window in the center of the screen. The items that display in the document window include the Form designer, code editor, project designer, database designer And object browser.
The Form Designer is where you design a form that makes up your user interface. The Solution Explorer Window holds the filenames for the files included in your project and list of the classes It references. The Properties Window set properties for the objects in Your project. The Toolbox holds the tools you use to place controls on a form.
Three distinct modes are: Design time Run time Debug time
Writing Your First C# Project • Select Visual C# / Windows / Windows Form Application / Enter name Hello world for the name of The new project. Note: Customizing windows, floating and docking
Plan the Sketch of the Hello World form • Define user interface and place of the controls on the form. • Set the name , properties of the object and form. • Write codes The comment statement and hello world–Examples textBox1.Text = "hello world"; //Assign the message to the Text property.
The Assignment Statement –General Form Object.Property – Value Ending a program by executing a Method Object.Method() Examples: helloButton.Hide(); messageLabel.Show(); this.Close();
Syntax Errors • Breaking rules in punctuation, format or spelling. Run Time Errors • Project halts during execution • C# display dialog box and highlight statement causing the Problem. Logic Errors • Program runs but produces in correct results. • Beginners in programming often overlook their logic errors.
Design a layout of a program for the great body gym center to display promotions. Put statement Label for each buttons of the following department. Hands on Programming 1 Great Body gym Membership Maintenance soup Equipment and Accessories Clothing Instructor Exit Programmed by <Your Name>
Hands on Programming 2 Design any program that will use the following objects: 2 Text Box 4 Label Box 1 Picture 4 Radio Buttons 3 Button 4 Check Box ex
Hands on Programming 3 This neighborhood store is an independently owned rental business. The owners would like to allow their customer to user the computer to look up aisle number for movies by category. Create a form with a button for each category. When the user clicks on a button, display the corresponding aisle number in a label. Include a button to exit. Include a button that holds your name at the bottom of the form and change the title bar of the form to Generation X Cinema. You may change font properties of the labels and size of your choice.
Clearing Text Boxes and Labels. • Display a Photo upon selection • Disabling Controls • Setting Properties • Changing the color of text • Using radio buttons for selecting colors • Concatenating Text • Printing a Form
Data – Variable and Constant • Memory locations that hold data that can be changed during project execution are variables. • Locations that hold data that cannot change during execution are called constants.
Naming Rules • Consist of letters, digits and underscores • Begin with letter or underscore • Must not contain of spaces or period • Not a reserve word or keywords
Naming Conventions • Identifier must be meaningful • Begin with a lowercase letter and capitalize each successive word of the name. Sample Identifiers Field of Data Possible Identifier Social security number socialSecurityNumberString Pay rate payRateDecimal Tax rate(constant) TAX_RATE_Decimal Population populationLong
Quiz Indicate whether each of the following identifiers conforms to the rules of c# and to the naming convention. If the identifier is invalid ,give the reason. 0. omitted 6. subString • #SoldInteger 7. Text • Number Sold Integer 8. maximum • Number.Sold.Integer 9. minimumRate • Amount$Decimal 10. maximumCheckDecimal • Class 11. companyNameString
ANSWER 0. omitted does not have a suffix indicate data type • #SoldInteger cannot contain character such as # • Number Sold Integer cannot contain blank spaces • Number.Sold.Integer period use only to separate item such Object.Property • Amount$Decimal cannot contain character such as $ • Class class is a reserve word • subString valid • Text reserve word • Maximum does not indicate clearly data type • minimumRate a suffix indicate data type used • maximumCheckDecimal valid • companyNameString valid
Declaration statement example string customerNameString; string customerNameString = “None”; int totalSoldInteger = 0; float temperatureFloat; float temperatureFloat= 32f; decimal priceDecimal;
Declaration statement example string customerNameString; string customerNametring = “None”; int totalSoldInteger = 0; float temperatureFloat; float temperatureFloat= 32f; decimal priceDecimal;
The MessageBox Statement General Form MessageBox.Show(TextMessage, TitlebarText, MessageButtons, MessageIcon); MessageBox.Show(“Enter numeric data.”); MessageBox.Show(“Try Again.”, “Data Eror”); MessageBox.Show(“This is a message.””This is a title bar”, Messagebuttons.OK);
Controlling Code Flow Comparison Operator – compare data and return either true or false result. It can be used to compare strings, numbers and even Booleans. comparison operator Meaning == is equal to != not equal to > greater than < Less than >= Greater than or equal to <= Less than or equal to
Controlling Code Flow Logical Operators – combine comparison results and create compound expression. Operator Description && Returns a value of true if both values are true || Returns a value of true if either value is true ! Inverts the true or false result