chapter 2

15
Its all just code by group 8 张张张 张张张 张张张 张张张张 张张张 ,,,, chapter 2

Upload: preston-moss

Post on 30-Dec-2015

18 views

Category:

Documents


1 download

DESCRIPTION

chapter 2. Its all just code by group 8 张亚东,杨杰,甘伟,余青龙,肖春亮. IDE is a powerful tool. - PowerPoint PPT Presentation

TRANSCRIPT

Its all just code

by group 8张亚东,杨杰,甘伟,余青龙,肖春亮

chapter 2

IDE is a powerful tool Every time you in the IDE in modify your project or drag something, it

automatically create the code. It is very good at writing sample code, or code that can be reused easily whitout requiring much customization

Every time you in the IDE make some change, it will change code, this means changing contain code files. Sometimes just to change a few lines, but sometimes also can add file to projects.

Where programs come from

Every program starts out as source code files The. NET Framework gives you the right

tools for the job Build the program to create an executable Your program runs inside the CLR

IDE help you coding

1.Solutions browser to show you to the project everything You will be in class switch back and forth between, the easiest way is to use solution browser. It has two kinds of views: solutions view (shown in the project files) and class view (display your code is how in logic division to different category).

2.Using tabs in open files switch between Because your program scattered on multiple files, always have multiple files at the same time open. Each open files can be in code editor in his own tags pages. IDE in has not saved filename before display a the asterisk (*).

3.IDE help you write the code Intelligent inductive characteristics do one thing for you showed this line possible next completed way

4.error list help you find a compiler error When you generate your solution, any block up the compiler issues will be displayed in the IDE at the bottom of the error list window inside.

When you change things in the IDE, you’re also changing your code

It’s always easier to the IDE to change your form’s Designer-generated code. But when you do, any change you make in the IDE ends up as a change to your project’s code.

Anatomy of a programEvery C# program’s code is structured in exactly the same way. All programs use namespaces, classes, and methods, to make your code easier to manage.

Anatomy of a program

1.The code file starts by using the .NET Framework tools

2.C# programs are organized into classes 3.Classes contain methods that perform

actions 4.A statement performs one single action

Your programs use variables to work with data

1.Declare your variables 2. Variables vary 3.You have to assign values to variables before

you use them 4.A few useful types 5.C# uses familiar math symbols 6.Loops perform an action over and over again 7.Use a code snippet to write simple for loops

Your programs use variables to work with data

Time to start codingThe real work of any program is in its statements. But statements don’t exist in a vacuum. So let’s set the stage for digging in and getting some code written. Create a new Windows Forms Application project.

Your programs use variables to work with data

Add statements to show a messageGet started by double-clicking on the first button. Then add these 6 statements to the button1_Click() method. Look closely at the code, and the output it produces.

Your programs use variables to work with data

If/else statements make decisionsUse if/else statements to tell your program to do certain things only when the conditions you set up are (or aren't) true. A lot of if/else statements check if two things are equal. That’s when you use the==operator. That’s different from the single equal sign(=)operator, which you use to set a value.

Set up conditions and see if they’re true

Use logical operators to check conditionsYou’re just looked at the == operator, which you use to test whether two variables are equal. There are a few other operators, too. Don’t worry about memorizing them right now—you’ll get to know them over the next few chapters:

1.The != operator works a lot like == except it’s true if the two things you’re comparing are not equal.

2.You can use > and < to compare numbers and see if one is bigger or smaller than the other.

3.The ==,!=, >, and < are called conditional operators. When you use them to test two variables or values, it’s called performing a conditional tests.

4.You can combine individual conditional tests into one long test using the && operator for AND and the || operator for OR. So to check if i equals 3 or j is less than 5, do (i==3)||(j<5).

Set up conditions and see if they’re true

Set a variable and then check it’s valueHere’s the code for the second button. It’s an if/else statement that checks an integer variable called x to see if it’s equal to 10.