Vous êtes sur la page 1sur 2

....You can use switch only on primitive data types, such as int or string.

With any other types (including float and double), you have to use an if statement. ..The case labels must be constant expressions, such as 42 or 42 . If you n eed to calculateyour case label values at run time, you must use an if statement. ..The case labels must be unique expressions. In other words, two case l abels cannot have the same value ..You can specify that you want to run the same statements for more than one value by providing a list of case labels and no intervening statements, in which case the code for the final label in the list is executed for all cases in that list. However, if a label has one or more associated statements, execution cannot fall through to subsequent label s, and the compiler generates an error Note::The break statement is the most common way to stop fall-through, b ut you can also use a return statement or a throw statement. ....note:: we cannot use the checked and unchecked keywords to control floatingp oint (noninteger) arithmetic. The checked and unchecked keywords apply only to intege r arithmetic using data types such as int and long. Floating-point arithmetic neve r throws OverflowException not even when you divide by 0.0. (The .NET Framework has a repre sentation for infinity.) ....Suppose you are implementing a method called monthName that accepts a single int argument and returns the name of the corresponding month. For example, monthName (1) returns January , monthName(2) returns February , and so on. The question is: What sho uld the method return if the integer argument is less than 1 or greater than 12? The best answer is that the method shouldn t return anything at all; it should throw an exception. .....Classes provide a convenient mechanism for modeling the entities manipulate d by applications. ....An entity can represent a specific item, such as a customer, or something more abstract, such as a transaction. Part of t he design process of any system is concerned with determining the entities that are import ant to the processes that the system implements, and then performing an analysis to see wha t information these entities need to hold and what operations they should perform ....Encapsulation actually has two purposes: 1. To combine methods and data inside a class; in other words, to support classi fication 2. To control the accessibility of the methods and data; in other words, to cont rol the use of the class.

....remember that variables in a class are called fields. ....Don t get confused between the terms class and object. A class is the definiti on of a type. An object is an instance of that type, created when the program runs.

Vous aimerez peut-être aussi