OBJ FINAL review 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What are the parts of a class definition in C#?

An optional access modifier The keyword class Any legal identifier you choose for the name of your class

Explain how to use AND and OR appropriately.

Beginning programmers often use the AND operator when they mean to use OR, and often use OR when they should use AND. Part of the problem lies in the way we use the English language

Briefly explain how to overload constructors.

as their argument lists do not cause ambiguity.

What is the role of a method in an object?

changing attributes and discovering the values of attributes

What is required to make a while loop end correctly?

* A variable, the loop control variable, is initialized (before entering the loop). * The loop control variable is tested in the while expression. * The body of the while statement must take some action that alters the value of the loop control variable (so that the while expression eventually evaluates as false).

List the DialogResult values

* Abort * Cancel * Ignore * No * None * OK * Retry * Yes

Why might a finally block be necessary?

* An Exception for which you did not plan might occur. * The try or catch block might contain a statement that quits the application

What are the significant parts of the Visual C# automatically generated code?

* Comments * The Dispose() method * Object declarations * The InitializeComponent() method * Preprocessor directives * A Main() method

What are the three default stream objects created when a C# application executes?

* Console.In refers to the standard input stream object, which accepts data from the keyboard. * Console.Out refers to the standard output stream object, which allows a program to produce output on the screen. * Console.Error refers to the standard error stream object, which allows a program to write error messages to the screen.

Describe some of the methods of the Directory class.

* CreateDirectory() creates a directory * Delete() deletes a directory * Exists() returns true if the specified directory exists * GetCreationTime() returns a DateTime object specifying when a directory was created * GetDirectories() returns a string array that contains the names of the subdirectories in the specified directory * GetFiles() returns a string array that contains the names of the files in the specified directory * GetLastAccessTime() returns a DateTime object specifying when a directory was last accessed * GetLastWriteTime() returns a DateTime object specifying when a directory was last modified * Move() moves a directory to the specified location

What are the disadvantages to writing to a text file?

* Data in a text file is easily readable in a text editor such as Notepad. Although this feature is useful to developers when they test programs, it is not a very secure way to store data. * When a record in a data file contains many fields, it is cumbersome to convert each field to text and combine the fields with delimiters before storing the record on a disk

What are the benefits of writing a useful, extendable base class?

* Derived class creators save development time because much of the code that is needed for the class already has been written. * Derived class creators save testing time because the base class code already has been tested and probably used in a variety of situations. In other words, the base class code is reliable. * Programmers who create or use new derived classes already understand how the base class works, so the time it takes to learn the new class features is reduced. * When you create a derived class in C#, the base class source code is not changed. Thus, the base class maintains its integrity.

Explain how the following code executes: if(saleAmount > 1000) if(saleAmount < 2000) bonus = 100; else bonus = 50;

* If saleAmount is between $1000 and $2000, bonus is $100 because both evaluated expressions are true. * If saleAmount is $2000 or more, bonus is $50 because the first evaluated expression is true and the second one is false. * If saleAmount is $1000 or less, bonus is unassigned because the first evaluated expression is false and there is no corresponding else.

What are the requirements for writing your own Equals() method?

* Its header should be as follows (you can use any identifier for the Object parameter): public override bool Equals(Object o) * It should return false if the argument is null. * It should return true if an object is compared to itself

What are the features offered by object-oriented programming?

* Objects * Classes * Encapsulation * Interfaces * Polymorphism * Inheritance

What is the class hierarchy of the Form class?

* Object * MarshalByRefObject * Component * Control * ScrollableControl * ContainerControl * Form

Describe some of the methods of the File class.

Create() creates a file * CreateText() creates a text file * Delete() deletes a file * Exists() returns true if the specified file exists * GetCreationTime() returns a DateTime object specifying when a file was created * GetLastAccessTime() returns a DateTime object specifying when a file was last accessed * GetLastWriteTime() returns a DateTime object specifying when a file was last modified * Move() moves a file to the specified location

What is the difference between reference parameters and output parameters?

When you declare a reference parameter in a method header, the parameter must have been assigned a value; in other words, in the calling method, any argument must be a constant or a variable with an assigned value. * When you use an output parameter, it need not contain an original value. However, an output parameter must receive a value before the method ends.

What are the advantages of placing classes within the same file?

reduce development time and simplify the compilation process.

What are the parts of a C# method declaration?

* Optional declared accessibility * An optional static modifier * The return type for the method * The method name, or identifier * An opening parenthesis * An optional list of method parameters (you separate the parameters with commas if there is more than one) * A closing parenthesis

What are the optional declared accessibility levels in C#?

* Public access, which you select by including a public modifier in the member declaration. This modifier allows unlimited access to a method. * Protected internal access, which you select by including both a protected and an internal modifier in the member declaration. This modifier limits method access to the containing program or types derived from the containing class. * Protected access, which you select by including a protected modifier in the member declaration. This modifier limits method access to the containing class or types derived from the containing class. * Internal access, which you select by including an internal modifier in the member declaration. This modifier limits method access to the containing program. * Private access, which you select by including a private modifier in the member declaration. This modifier limits method access to the containing type.

What is the information included in a variable declaration?

* The data type that the variable will store * The identifier that is the variable's name * An optional assignment operator and assigned value when you want a variable to contain an initial value * An ending semicolon

What are the keywords used in a switch structure?

* The keyword switch starts the structure and is followed immediately by a test expression (called the switch expression) enclosed in parentheses. * The keyword case is followed by one of the possible values that might equal the switch expression. A colon follows the value. The entire expression—for example, case 1:—is a case label. A case label identifies a course of action in a switch structure. Most switch structures contain several case labels. * The keyword break usually terminates a switch structure at the end of each case. Although other statements can end a case, break is the most commonly used. * The keyword default optionally is used prior to any action that should occur if the test expression does not match any case.

What are some of the key features in the Visual C# IDE?

* The main menu, which includes a File menu from which you open, close, and save projects. It also contains submenus for editing, debugging, and help tasks, among others. * The Toolbox, which provides a list of controls you can drag onto a Form so that you can develop programs visually, using a mouse. * The Form Designer and Code Editor, which appear in the center of the screen. You can switch back and forth between these two when you want to design an application by dragging components onto the screen or when you want to write or view code statements. * The Solution Explorer, for viewing and managing project files and settings. * The Properties window, for configuring properties and events on controls in your user interface. * The error list, which displays any compiler errors in your code.

What are the overloadable unary and binary operators in C#? What operators cannot be overloaded?

* The overloadable unary operators are: + - ! ~ ++ -- true false * The overloadable binary operators are: + - * / % & | ^ == != > < >= <= * You cannot overload the following operators: = && || ?? ?: checked unchecked new typeof as is

What are the three classes from which most exceptions you will use derive?

* The predefined Common Language Runtime exception classes derived from SystemException * The user-defined application exception classes you derive from ApplicationException * The Exception class, which is the parent of SystemException and ApplicationException

Describe some of the characteristics of the Dispose() method.

* This method is protected, meaning any descendants can access it. * The method header uses the term override, meaning it overrides a method with the same name in an interface named IDisposable. That interface provides a mechanism for releasing program resources, such as files, that can be used by only one program at a time. This method contains any cleanup activities you need when a Form is dismissed. When you write an application that leaves open files or other unfinished business, you might want to add statements to this method. * The method's return type is void, so the method returns nothing to any method that calls it. * The method accepts a bool parameter. * The method includes an if statement and a call to another method that resides in its base class.

What are some of the methods that you can use with the SelectionStart and SelectionEnd properties of MonthCalendar?

* ToShortDateString(), which displays the date in the format 2/13/2009 * ToLongDateString(), which displays the date in the format Friday, February 13, 2009 * AddDays(), which takes a double argument and adds a specified number of days to the date * AddMonths(), which takes an int argument and adds a specified number of months to the date * AddYears(), which takes an int argument and adds a specified number of years to the date

Regarding if statements, what are the situations in which programmers often make errors?

* When performing a range check incorrectly or inefficiently * When using the wrong operator with AND and OR * Using NOT incorrectly

What tasks can be performed in the three sections of a for loop?

* You can initialize more than one variable by placing commas between the separate statements, as in the following: for(g = 0, h = 1; g < 6; ++g) * You can declare a new variable, as in the following: for(int k = 0; k < 5; ++k)

Describe the circumstances where you can use the foreach statement.

* You typically use foreach only when you want to access every array element; to access only selected array elements, you must manipulate subscripts using some other technique—for example, using a for loop or while loop. * The foreach iteration variable is read-only—that is, you cannot assign a value to it. If you want to assign a value to array elements, you must use a different type of loop.

Describe the main characteristics of two-dimensional arrays.

. Two-dimensional arrays have two or more columns of values for each row. In a rectangular array, each row has the same number of columns

Write two short segments of code that print the integers 1 through 10. One segment should use a while and the other should use a for loop.

// Declare loop control variable and limit int x; const int LIMIT = 10 // Using a while loop to display 1 through 10 x = 1; while(x <= LIMIT) { Console.WriteLine(x); ++x; } // Using a for loop to display 1 through 10 for(x = 1; x <= LIMIT; ++x) Console.WriteLine(x);

What is a character?

A character is any one of the letters, numbers, or other special symbols (such as punctuation marks) that comprise data.

What is a field?

A field is a character or group of characters that has some meaning.

Briefly describe three of the C# mechanisms to create loops

A while loop, in which the loop-controlling Boolean expression is the first statement in the loop * A for loop, which is usually used as a concise format in which to execute loops * A do loop (or do-while loop), in which the loop-controlling Boolean expression is the last statement in the loop

Explain the MessageBoxButtons values

AbortRetryIgnore The message box contains Abort, Retry, and Ignore buttons OK The message box contains an OK button OKCancel The message box contains OK and Cancel buttons RetryCancel The message box contains Retry and Cancel buttons YesNo The message box contains Yes and No buttons YesNoCancel The message box contains Yes, No, and Cancel buttons

Explain the arguments passed to at least six versions of the MessageBox.Show() method

Argument to MessageBox.Show() Explanation string Displays a message box with the specified text string, string Displays a message box with the specified text and caption string, string, MessageBoxButtons Displays a message box with specified text, caption, and buttons string, string, MessageBoxButtons, MessageBoxIcon Displays a message box with specified text, caption, buttons, and icon string, string, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton Displays a message box with the specified text, caption, buttons, icon, and default button string, string, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions Displays a message box with the specified text, caption, buttons, icon, default button, and options

Explain the arguments passed to at least six versions of the MessageBox.Show() method.

Argument to MessageBox.Show() Explanation string Displays a message box with the specified text string, string Displays a message box with the specified text and caption string, string, MessageBoxButtons Displays a message box with specified text, caption, and buttons string, string, MessageBoxButtons, MessageBoxIcon Displays a message box with specified text, caption, buttons, and icon string, string, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton Displays a message box with the specified text, caption, buttons, icon, and default button string, string, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions Displays a message box with the specified text, caption, buttons, icon, default button, and options

What are some of the commonly used CheckBox properties and default event?

Checked Indicates whether the CheckBox is checked CheckState Indicates whether the CheckBox is checked, with a value for the CheckState enumeration (Checked, Unchecked, or Indeterminate) Text The text displayed to the right of the CheckBox CheckedChanged() Default event that is generated when the Checked property changes

What are the two types of classes supported by C#?

Classes that are only application programs with a Main() method. These classes can contain other methods that the Main() method calls. * Classes from which you instantiate objects; these classes can contain a Main() method, but it is not required.

Briefly describe some of the ways to access Help while working in Visual C#.

F1 Search—In the Code Editor, you can position the cursor on or just after a keyword or class member and press F1. The Help provided is context-sensitive, which means the screen you see depends on where your cursor is located. * Search—On the main menu, you can click Help, click Search, and type in a topic. * Index—You can select Help from the main menu and click Index. The index provides a quick way to locate documents in your local MSDN library. It searches only the index keywords that have been assigned to each document. * Table of Contents—The MSDN library table of contents shows all the topics in the library in a hierarchical tree structure. * How Do I—How Do I provides a view of MSDN documents called How-to's or Walkthroughs. These documents show you how to perform a specific task. * Dynamic Help—Dynamic Help provides a way to get information about the IDE. To open the Dynamic Help window, select Help from the main menu, and then click Dynamic Help. Then, when you click a word in the code, help topics are displayed accordingly.

What do you need to do to make a Button clickable?

For a Button to be clickable, you need to use the System.Windows.Forms.Control class, which implements very basic functionality required by any classes that display GUI objects to the user

List some of the implicit numeric conversions supported by C#.

From sbyte to short, int, long, float, double, or decimal * From byte to short, ushort, int, uint, long, ulong, float, double, or decimal * From short to int, long, float, double, or decimal * From ushort to int, uint, long, ulong, float, double, or decimal * From int to long, float, double, or decimal * From uint to long, ulong, float, double, or decimal * From long to float, double, or decimal * From ulong to float, double, or decimal * From char to ushort, int, uint, long, ulong, float, double, or decimal * From float to double

Under what circumstances does the BinarySearch() method prove inadequate?

If your array items are not arranged in ascending order, the BinarySearch() method does not work correctly. * If your array holds duplicate values and you want to find all of them, the BinarySearch() method doesn't work—it can return only one value, so it returns the position of the first matching value it finds. This matching position is the one closest to the middle of the array. * If you want to find a range match rather than an exact match, the BinarySearch() method does not work.

What are some of the commonly used PictureBox properties and default event?

Image Sets the image that appears in the PictureBox SizeMode Controls the size and position of the image in the PictureBox; values are Normal, StretchImage (which resizes the image to fit the PictureBox), AutoSize (which resizes the PictureBox to fit the image), and CenterImage (which centers the image in the PictureBox) Click() Default event that is generated when the user clicks the PictureBox

the types of comments supported by C#?

Line comments start with two forward slashes (//) and continue to the end of the current line. Line comments can appear on a line by themselves, or at the end of a line following executable code. * Block comments start with a forward slash and an asterisk (/*) and end with an asterisk and a forward slash (*/ ). Block comments can appear on a line by themselves, on a line before executable code, or after executable code. When a comment is long, block comments can extend across as many lines as needed. * C# also supports a special type of comment used to create documentation from within a program. These comments, called XML-documentation format comments, use a special set of tags within angle brackets (<>).

What are some of the commonly used MonthCalendar properties and default event?

MaxDate Sets the last day that can be selected (the default is 12/31/9998) MaxSelectionCount Sets the maximum number of dates that can be selected at once (the default is 7) MinDate Sets the first day that can be selected (the default is 1/1/1753) MonthlyBoldedDates An array of dates that appear in boldface in the calendar; for example, holidays SelectionEnd The last of a range of dates selected by the user SelectionRange The dates selected by the user SelectionStart The first of a range of dates selected by the user ShowToday If true, the date displays in text at the bottom of the calendar ShowTodayCircle If true, today's date is circled (the "circle" appears as a square) DateChanged() Default event that is generated when the user selects a date

Explain the MessageBoxButtons values.

Member Name Description AbortRetryIgnore The message box contains Abort, Retry, and Ignore buttons OK The message box contains an OK button OKCancel The message box contains OK and Cancel buttons RetryCancel The message box contains Retry and Cancel buttons YesNo The message box contains Yes and No buttons YesNoCancel The message box contains Yes, No, and Cancel buttons

Briefly describe the four public methods of the Object class.

Method Explanation Equals() Determines whether two Object instances are equal GetHashCode() Gets a unique code for each object; useful in certain sorting and data management tasks GetType() Returns the type, or class, of an object ToString() Returns a String that represents the object

What are some of the reasons why a method throws more than three or four types of exceptions?

Perhaps the method is trying to accomplish too many diverse tasks and should be broken up into smaller methods. * Perhaps the Exception types thrown are too specific and should be generalized

What are some of the commonly used LinkLabel properties and default event?

Property or Method Description ActiveLinkColor The color of the link when it is clicked LinkColor The original color of links before they have been visited; usually blue by default LinkVisited If true, the link's color is changed to the VisitedLinkColor VisitedLinkColor The color of a link after it has been visited; usually purple by default LinkClicked() Default event that is generated when the link is clicked by the user

How does short-circuit evaluation work?

The expressions in each part of an AND expression are evaluated only as much as necessary to determine whether the entire expression is true or false

Describe the structure of a catch block.

The keyword catch * Parentheses containing an Exception type, and optionally, a name for an instance of the Exception type * A pair of curly braces containing statements that deal with the error condition

Briefly describe a try block.

The keyword try * A pair of curly braces containing statements that might cause Exceptions

What is a default event for a Control?

The method whose shell is automatically created when you double-click the Control while designing a project in the IDE * The method that you are most likely to alter when you use the Control * The event that users most likely expect to generate when they encounter the Control in a working application

Explain the use of protected fields.

The solution is to create the empSal field using the modifier protected, which provides you with an intermediate level of security between public and private access.

Describe the main characteristics of two-dimensional arrays

Two-dimensional arrays have two or more columns of values for each row

What are the most frequent errors new programmers frequently make when they first learn to make decisions?

Using the assignment operator instead of the comparison operator when testing for equality * Inserting a semicolon after the Boolean expression in an if statement instead of after the entire statement is completed * Failing to block a set of statements with curly braces when several statements depend on the if or the else statement * Failing to include a complete Boolean expression on each side of an && or || operator in an if statement

What are the four kinds of formal parameters supported by C#?

Value parameters, which are declared without any modifiers * Reference parameters, which are declared with the ref modifier * Output parameters, which are declared with the out modifier * Parameter arrays, which are declared with the params modifier

Why are all computer decisions yes-or-no decisions?

When reduced to their most basic form, all computer decisions are yes-or-no decisions

What are the differences between the prefix increment and the postfix increment operators?

When you only want to increase a variable's value by 1, there is no apparent difference between using the prefix and postfix increment operators. However, these operators function differently. When you use the prefix ++, the result is calculated and stored, and then the variable is used. In contrast, when you use the postfix ++, the variable is used, and then the result is calculated and stored.

Explain how to assign a value to an array element and how to print it.

When you work with any individual array element, you treat it no differently than you treat a single variable of the same type

How do nested method calls work?

When you write a statement with three nested method calls like the previous statement, the innermost method executes first

Provide an example of a way to improve a loop's performance

Whether you decide to use a while, for, or do-while loop in an application, you can improve loop performance by making sure the loop does not include unnecessary operations or statements

Explain how to allow single selection and multiple selections with a ListBox.

With a ListBox, you allow the user to make a single selection or multiple selections by setting the SelectionMode property appropriately.

Explain how to change the value of a loop control variable

Within a correctly functioning loop's body, you can change the value of the loop control variable in a number of ways. Many loop control variable values are altered by incrementing, or adding to them.

Explain how to combine AND and OR operators.

You can combine as many AND and OR operators in an expression as you need. For example, when three conditions must be true before performing an action, you can use an expression such as if(a && b && c).

Explain how to create a Font using three arguments.

You can create a Font using three arguments, adding a FontStyle

Describe the use of contextual keywords in C#. Use a set accessor as an example.

You can declare variables within a set accessor, but you cannot declare one named value. However, in other C# methods, you can declare a variable named value if you want

Explain how to create a Label.

You can manually create a Label by using the class name and an identifier and then calling the class constructor

Explain how to catch multiple Exceptions.

You can place as many statements as you need within a try block, and you can catch as many different Exceptions as you want.

Explain how to use base class constructors that require arguments.

Your derived class constructor can contain any number of statements; however, within the header of the constructor, you must provide values for any arguments required by the base class constructor. Even if you have no other reason for creating a derived class constructor, you must write the derived class constructor so it can call its parent's constructor. The format of the portion of the constructor header that calls a base class constructor is base(list of arguments).

Mention some of the types of potential exceptions that can be generated by a C# program

Your program asks for user input, but the user enters invalid data. * The program attempts to divide a value by zero. * You attempt to access an array with a subscript that is too large or too small. * You calculate a value that is too large for the answer's variable type.

What are the main characteristics of the nine integral data types in C#?

byte, sbyte, short, ushort, int, uint, long, ulong, and char.

What are the main characteristics of the three floating-point data types in C#?

float, double, and decimal.

Explain how to use a loop to perform arithmetic on each element in an array.

for(int sub = 0; sub < 5; ++sub) myScores[sub] += 3;

Explain how to use a for loop to search an array for an exact match.

for(int x = 0; x < validValues.Length; ++x) if(itemOrdered == validValues[x]) isValidItem = true;

Write a short example of a for loop that includes a block of statements

for(var = 0; var < 4; ++var) { Console.WriteLine("Hello"); Console.WriteLine("Goodbye"); }

What is the meaning of the keyword static in C#?

indicates that the Main() method will be executed through a class—not by a variety of objects

How would you compare C# with Java?

java- simple data types are not objects c#- every piece of data is an object

the C# requirements when choosing an identifier?

must begin with an underscore, the at sign (@), or a letter. (Letters include foreign-alphabet letters such as B and S, which are contained in the set of characters known as Unicode.) can contain only letters or digits, not special characters such as #, $, or &. cannot be a C# reserved keyword, such as public or class. (Actually, you can use a keyword as an identifier if you precede it with an "at" sign, as in @class.

What are the advantages of placing classes in separate files?

organization class is easier to reuse within additional programs you create in the future

Explain with a code example how to access a method in the parent class

public class CommissionEmployee : Employee { private double commissionRate; public double CommissionRate { get { return commissionRate; } set { commissionRate = value; empSal = 0; } } new public string GetGreeting() { string greeting = base.GetGreeting(); greeting += "\nGood luck with sales!"; return greeting; } }

Write a ComputeSalesTax() method that receives a sales amount and a tax rate, and calculates and displays the sales tax.

public static void ComputeSalesTax(double saleAmount, double taxRate) { double tax; tax = saleAmount * taxRate; Console.WriteLine("The tax on {0} at {1} is {2}", saleAmount.ToString("C"), taxRate.ToString("P"), tax.ToString("F")); }

What are the class access modifiers in C#?

public, meaning access to the class is not limited. * protected, meaning access to the class is limited to the class and to any classes derived from the class. * internal, meaning access is limited to the assembly (a group of code modules compiled together) to which the class belongs. * private, meaning access is limited to another class to which the class belongs. In other words, a class can be private if it is contained within another class, and only the containing class should have access to the private class.

What are the attributes and states of an object?

represent its characteristics

How can you compare strings using the Compare() method?

requires two string arguments. When it returns 0, the two strings are equivalent; when it returns a positive number, the first string is greater than the second; and when it returns a negative value, the first string is less than the second.

Briefly describe the Reverse() method.

reverses the order of items in an array

What are the similarities and differences of abstract classes and interfaces?

similar - you cannot instantiate concrete objects from either one. different - abstract classes can contain nonabstract methods, but all methods within an interface must be abstract

How can you create a constant in C#?

similarly to the way you create a named variable, but by using the keyword const.

Why is it important to initialize a total variable?

the program will not compile

Explain the main characteristics of encapsulation.

the technique of packaging an objects attributes and methods into a cohesive unit that can be used as an undivided entity

Explain how to accept user input from the keyboard using the Console.ReadLine() method

to accept user input from the keyboard. This method accepts all of the characters entered by a user until the user presses Enter.

How does the conditional operator work

used as an abbreviated version of the if-else statement; it requires three expressions separated with a question mark and a colon.

How can you compare strings in C# using the CompareTo() method?

uses a string, a dot, and the method name. The string to compare to is placed within parentheses

Write a code example to show that every object "is an" Object.

using System; class DiverseObjects { public static void Main() { Student payingStudent = new Student(); ScholarshipStudent freeStudent = new ScholarshipStudent(); Employee clerk = new Employee(); Console.Write("Using Student: "); DisplayObjectMessage(payingStudent); Console.Write("Using ScholarshipStudent: "); DisplayObjectMessage(freeStudent); Console.Write("Using Employee: "); DisplayObjectMessage(clerk); } public static void DisplayObjectMessage(Object o) { Console.WriteLine("Method successfully called"); } }

Write an example of ambiguous methods.

using System; public class AmbiguousMethods { public static void Main() { int iNum = 20; double dNum = 4.5; SimpleMethod(iNum, dNum); // calls first version SimpleMethod(dNum, iNum); // calls second version SimpleMethod(iNum, iNum); // error! Call is ambiguous. } public static void SimpleMethod(int i, double d) { Console.WriteLine("Method receives int and double"); } public static void SimpleMethod(double d, int i) { Console.WriteLine("Method receives double and int"); } }

Write a short program that prints "Hello" on the console four times using a while loop

using System; public class FourHellos { public static void Main() { int number = 1; while(number < 5) { Console.WriteLine("Hello"); number = number + 1; } } }

Write a small program that uses the Sort() method

using System; public class SortArray { public static void Main() { string[] names = {"Olive", "Patty", "Richard", "Ned", "Mindy"}; int x; Array.Sort(names); for(x = 0; x < names.Length; ++x) Console.WriteLine(names[x]); } }

Write a small program that uses the Sort() method.

using System; public class SortArray { public static void Main() { string[] names = {"Olive", "Patty", "Richard", "Ned", "Mindy"}; int x; Array.Sort(names); for(x = 0; x < names.Length; ++x) Console.WriteLine(names[x]); } }

When should you handle exceptions with a loop?

want to display an error message when an Exception occurs remedy the situation the same way every time, such as setting a result to 0

Briefly describe the structure of a for loop.

with the keyword for followed by a set of parentheses. Within the parentheses are three sections separated by exactly two semicolons

Explain how to work with base classes that have constructors.

you call both the constructor for the base class and the constructor for the extended, derived class.

How can you change the size of an array in C#?

you can assign five elements later with array = new int[5];;

Compare GroupBox and Panel objects.

you can use a GroupBox or Panel to group related Controls on a Form. When you move a GroupBox or Panel, all its Controls are moved as a group.

How can you explicitly throw an exception in C#?

you can't throw an object unless it is an Exception or a descendant of the Exception class

How can you create a class that can be serializable?

you mark it with the [Serializable] attribute

Explain how to declare a method that can receive a parameter

you need to include the following items within the method declaration parentheses: * The type of the parameter * A local identifier (name) for the parameter

What is the two-step process for creating objects?

you supply a type and an identifier you create the object, which includes allocating computer memory for it

How can you create a child class in C#?

you use a single colon between the derived class name and its base class name

Explain the main characteristics of inheritance.

Provides the ability to extend a class so as to create a more specific class

When does a finally block execute?

The try ends normally. * The catch executes. * An Exception causes the method to abandon prematurely

What is a record?

A record is a collection of fields that contain data about an entity.

What are the parts of a C# method?

contains a header and a body.

Briefly explain how to create instance variables.

create an attribute to hold a value that describes a feature of every object of that class.

How can you reread a sequential file?

just reposition the file pointer using the Seek() method and the SeekOrigin enumeration.

What is the principle of implementation hiding?

keeping the details of a method's operations hidden

What are the steps to create a Form that is a program's main window?

* You must derive a new custom class from the base class System.Windows.Forms.Form. * You must write a Main() method that calls the Application.Run() method, and you must pass an instance of your newly created Form class as an argument. This activity starts the program and makes the form visible.

What is a data file?

. Data files consist of related records, such as a company's personnel file that contains one record for each company employee

How can you assign nondefault values to array elements upon creation?

. To initialize an array to nondefault values, you use a list of values that are separated by commas and enclosed within curly braces

Explain how to use NOT correctly.

Whenever you use negatives, it is easy to make logical mistakes


संबंधित स्टडी सेट्स

Fin 201 Ch.4 Time Value of Money

View Set

Web Application & Software Architecture 101

View Set

CHEM 112 SB ELECTROCHEMISTRY ASSIGNMENT

View Set

Quiz 4 Prep (Source 24.4: Militant Suffrage-Emmeline Pankhurst) *Credits to Aniston for Answers to Source Interpretation Q's!

View Set

Care of Patients with Endocrine Disorders Chapter 37

View Set

MODULE 10: Ch. 42 (Fluid & Electrolytes) - FLUID BALANCE

View Set

Research Methods Psychology Exam 1

View Set

Achieve3000: Lesson - Changing Mines

View Set

US Ch. 4: Civil Liberties: Protecting Individual Rights

View Set