Midterm

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What would the String.Format arguments be to (1) insert a floating dollar sign (2) commas as necessary and (3) exactly two digits after the decimal point? Quiz What would be the correct String.Format to use, to express 1234.567 (referred to below as "slacker") as $1,234.5

"${0: 0,0.00}", slacker

Left Justification String format

"{0, -10: 0.00}" ---- 10 space left justification String.Format("{0, -10: 0.00}", 3.14159265) Results: print '3.14 '

What would the String.Format arguments be to display a decimal as a percentage? Quiz Which of the following String.Format arguments would correctly display 0.1544 as 15.44%?

"{0: 0.00%}", slacker

How to find size of list

.Length courseStringArray.Length != 2

Assume I have an enumerated type called "PowerLifters". What would be the output from Console.WriteLine("{0}", (PowerLifters)100), assuming 100 isn't a valid value in this enumeration? Quiz Let's say I have the following enumeration defined public enum Prinny { Kurtis, Big Sis, Fubuki, Nemo, Baal = 9999 }; What would the output from the following command be: Console.WriteLine("{0}, dood!", (Prinny) 4);

4, dood!

What is an indexer?

A definition for how the subscript notation [] is used in relation to a class

What is a LinkedList?

A doubly-linked list Collection of Nodes LinkedList - double linked items, slower than ArrayList, good choice for fast insertion and deletion

What is a SortedSet?

A doubly-linked list Collection, which (1) preserves sorted order as elements are added and (2) prohibits duplicate elements. functionally similar to a LinkedList

What is a delegate?

A hard-coded reference to methods that share a method signature, which can call any number of them by calling the delegate method

What is a HashSet?

A high-performance, mathematical-set container, useful for leveraging set operations such as "union" and "intersection" Similar to linked list, but elements must be unique

What is a Property?

A public facing attribute, typically controlling read/write access to private attributes

What is an event?

A representation of an action taken by a user

What is a predicate?

A single-purpose delegate, used to generate a true/false value, based on programmer-defined logic

What are valid arguments to pass to a method, that accepts only a single, parameter array of integers? Quiz I have a public void method called slacker that takes a single, parameter array of integers as an argument. Which of the following method calls is NOT valid?

ALL ARE VALID slacker(); int[] arguments = {1, 8, 27, 64}; slacker(arguments); slacker(1729); PARAMS: public void simpleAdd(params int[] array) { }

What is an interface?

An abstract class containing exactly one method to be defined by other classes An interface is a class that only includes method signatures. The methods are not implemented in the interface. Another class must be created to supply the implementation. An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.

In relation to nullable types, what does ?? mean, or what does ?? do?

An alternate assignment, should a nullable variable be equal to null ?? notation you can use to define a default value when assigning a nullable type to a non-nullable type.

What is a List?

An automatically re-sizing array

What is a SortedDictionary?

An insert/remove-efficient Dictionary, which orders elements by their "key"

What is a Dictionary?

An oversized array where a "key" is used to generate an index where a "value" will be stored A mutable collection of key-value pairs.

How are relational comparisons of strings done?

By checking the return value of "CompareTo(string alpha)" if (alpha.CompareTo(beta) > 0)

What is a lambda expression or anonymous function?

Chunks of code with no formal name to be used or to refer to them by, giving way to the creation of sort of one-time use functions.

What is the name of the Form container that contains an attached button you click to expand a collapsible list of items to select from? QUIZ The name of the Form container with an attached button you click to expand a collapsible list of items to select from is called

ComboBox

"int slacker[2, 2]" is an example of which type of array?

Conventional, multi-dimensional arrays

Which type of inherited methods (virtual or abstract) must be implemented by derived classes? Quiz When I have a method defined as abstract, it " isn't " strictly speaking necessary for derived classes to re-implement this method. TRUE OR FALSE

FALSE Virtual methods do not necessarily need to be implemented by derived classes. Abstract methods, however, must have some implementation (even if its just { } ) by each and every derived class. abstract is the keyword used to describe something as having an incomplete or missing implementation, that must be overriden.

Generally speaking, what would be the output from input.Split()[2]? QUIZ string input = "And then one warm summer night I'll hear fireworks outside"; Console.WriteLine(String.Format("The fourth token is '{0}'.", input.Split()[3])); Will (1) not generate a compilation error and (2) print The fourth token is 'warm'. TRUE OR FALSE

FALSE "." is missing but accepted true

What is a Queue?

FIFO stack container It represents a first-in, first out collection of object collection of data kept in the order it was collected. You can only add from the back and remove from the front (line at BestBuy)

In relation to external file usage, what does the using keyword NOT cover? QUIZ In the context of external file usage, the using keyword handles the opening/closing of file streams, as well as protections against non-existent files or files the user has no permissions to read/write to.

False using statement acts as a sort of open/close function we might otherwise have had to call before/after the loop. but don't address the possibility of something going wrong with opening/using/closing these file streams if (File.Exists("input.txt"))

Which interface allows for arrays/collections of objects from a class, to be sorted?

IComparable

Which interface allows for Collections to be iterated through by foreach loops?

IEnumerable

Which interface allows for foreach loops to iterate through a SortedSet or a Dictionary collection? Quiz Which of the following interfaces allows for non-trivial collections (i.e. not arrays) to be iterated by foreach loops?

IEnumerable

What are the ways "using" can be... used, in our C# projects? Quiz The "using" keyword in C# can be used in which of the following ways:

Including namespace resources, such as "System.IO" Defining an alias for a namespace or type Simplify the allocation/de-allocation of temporary resources, such as file streams.

Give two examples of possible exceptions?

IndexOutOfRangeException, DivideByZeroException, NullPointerException, IOException, EndOfStreamException

What is an indexer? How would you code one? Quiz Refer back to our Student/Course class structures from Assignments 1 through 3. Let's say I want to include an indexer for my Course class to refer to one of the Students enrolled. Which of the following would be the correct header for this?

Indexers are a mechanism by which we can use square bracket notation [ ] to access attributes of a class. public uint this[int index] { /* get and set */ }

"int slacker[2][2]" is an example of which type of array?

Jagged arrays

What is a Stack?

LIFO stack container It represents a last-in, first out collection of object A stack is a data structure with elements of the *SAME* type. Data elements of the *stack* data structure can only be accessed (stored or retrieved) at one end of the stack in a *LIFO* manner.

Define how a SortedList collection behaves? Quiz Which of the following best describes how a SortedList collection functions?

Like a memory-efficient Dictionary, that orders the elements within.

What are the two types of events we've worked with the most so far?

Mouse events AND keyboard events

Nullable Types

Normal data types with addition of allowing to take on null values How to use string? myVar; Nullable<string> myOtherVar;

What is an exception?

Objects that are created if a specific (typically negative) event occurs during program execution

How do you define variables to possibly contain the value null?

Placing a ? after the date type or Nullable<T>

Properties

Properties are named members of classes, structures, and interfaces

What terms do we use to describe the two actors involved with events?

Publishers and subscribers

What is the only significant functional difference between ref and out?

REF is used to qualify arguments as being passed by reference, not by copy. The prerequisite here is that the argument must be initialized. Ex: public void myRefMethod(ref int alpha) { } OUT is functionally very similar, except there's no prerequisite that the argument be initialized. Ex: public void myOutMethod(out int alpha) { }

What is the correct syntax for defining a 3-dimensional conventional array of integers? QUIZ Which of the following is the correct declaration (and default initialization) of a 3 x 3 x 3 dimensional array of Slacker objects?

Slacker[ , , ] myArray = new Slacker[3, 3, 3];

"#" character String format

String.Format("{0: ##.00}", 0.283185) // Prints .28 String.Format("{0: #0.00}", 6.283185) // Prints 6.28 String.Format("{0: 0.##}", 6) // Prints 6

Comma character String format

String.Format("{0: 0,0}", 1729) // Prints 1,729 String.Format("{0: 0,0}", 399878993) // Prints 399,878,993

Zero character String format

String.Format("{0: 00.00}", 6.283185) // Prints 06.28 String.Format("{0: 0.00}", 6.283185) // Prints 6.28 String.Format("{0: 0.00}", 6.2) // Prints 6.20

StringBuilder

StringBuilder changes = convert; // "deadlift" changes.Replace('d', 'D', 0, 1); // Swap the 'd' character found at the beginning with 'D' • d - character replacing • D - character replacing with • 0 - index replacing • 1 - number or length of character

Example of Predicate and Lambda expression

Student myHero = Array.Find(enrolled,(Student alpha) => (alpha.firstExam < 65 && alpha.finalExam > 85));

what does the @ do in: string this_is_much_better = @"c:\My Documents\My Memes\gru_debugging.jpg";

The @ avoids the necessity of prefixing escape characters with \

What does the ?? notation represent?

The conditional assignment if a nullable type is being used

What is the difference between value and reference type variables?

Value type variables have a strong connection to a single piece of memory stored somewhere. • This includes enumerations, primitive data types (int, bool, char), and programmer-defined structs. Reference types do not contain values themselves but instead an address to where values can be found(basically a pointer to memory where a contiguous block of memory is found, containing a collection of homogeneous data) • Objects from a class, delegates, strings, Array, and variables referring to dynamically allocated memory, are all reference types.

A memory-efficient Dictionary, which orders elements by their "key" A collection that is a combination of key/value entries and an ArrayList. The collection is sorted by key.

What is a SortedList?

What is boxing/unboxing? Quiz The following: Infint palindromicPrime = "399878993"; object intermid = palindromicPrime; Infint slacker = (Infint)intermid; is an example of what?

When a value type variable is being implicitly converted to an object type by "Boxing it". Infint palindromicPrime = "399878993"; object intermid = palindromicPrime; // This "boxes" intermid into an Infint type Infint slacker = (Infint)intermid; // This "unboxes" the intermid

What is the correct syntax for calling a superclass' version of a derived method? Quiz Which of the following would be the correct syntax for calling a parent class' public virtual void print() method?

base.print();

How to get the value of radioButton that is checked

checkedButton.Text

How to know which item on comboBox is selected

comboBoxStudentGrade.SelectedIndex == 0

How to remove "Z" from Z5234567

computedZid.Remove(0, 1);

How to get value from numericUpDown

int selectedPercent = Convert.ToInt16(numericUpDownPercentage.Value);

?? Notation

int? slacker = null; int test = slacker ?? -1; This means: if slacker is not null, set test equal to its value. If it is null, set test to -1

Quiz The second argument described below Taxi cab = Array.Find(taxiDatabase, (Taxi target) => (target.number == 1729) ); is an example of what?

lambda expression or anonymous function.

What are the two arguments we've typically used for event handlers?

object Alpha, EventArgs Beta

Events header syntax

private void buttonStudentFailReport_Click(object sender, EventArgs e) { }

How do you define an indexer?

public <returnType> this[int index]

QUIZ When passing arguments by reference, which of the two methods will NOT require the argument to contain an initial value?

public void slacker(out int alpha)

What's the difference between readonly/const?

readonly is a subtle qualifier, that functions very similarly to const. They both permit a variable to be given an initial value and then to never have that value altered by your program. const variables are statically stored in memory, as compared to readonly which acts more like a reference to where that value will be found. The difference comes whenever you want to update those values, and which assemblies need to be re-compiled in order to correctly update.

How to assign value to richTextBox

richTextBoxMessage.Text = " Please type a Course";

how to check every character is numeric, 7 characters in total

string pattern = @"^[0-9]{7}$"; Match result = Regex.Match(computedZid,pattern);

How to Read file

string studentFile = @"2188_a3_input01.txt"; if (File.Exists(studentFile)) { try { using (StreamReader sr = File.OpenText(studentFile)) { String input; while ((input = sr.ReadLine()) != null) { string[] studentStringArray = input.Split(','); Student student = new Student(); students.Add(student); } } } catch { richTextBoxMessage.Text = "Unable to open File"; } //end of try-catch block } else { richTextBoxMessage.Text = " Student File not found"; Environment.Exit(0); } }

How to split value from a textBox

string[] courseStringArray = textBoxCourseGradeReport.Text.Split(' ');

Quiz Which of the following lists contain only reference type variables?

strings, LinkedLists , and arrays

When are NullPointerException triggered?

triggered whenever a piece of code attempts to refer to a null pointer, or use a reference type variable that's null

How to write LINQ way 1

var StageOne = from X in carDatabase where X.Make.CompareTo("Ford") == 0 where X.Make.CupHolders >= 4 select X; var StageTwo = from Y in StageOne where Y.Price <= 29999.99 where Y.Year >= 2016 group Y by Y.Model orderby Y.Color Ascending select Y;

How to know which radioButton is selected in a groupBox

var checkedButton = groupBoxFailReportAllCourses.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked);

How to write LINQ way 2

var stage1Grade = from student in students where student.major == major select student; var stage2Grade = from grade in Form1.grades from student in stage1Grade where grade.zid == student.zid && grade.DepartmentCode == courseDept && grade.CourseNumber == (uint)int.Parse(courseNum) && grade.numericGradeValue < Grade.NumericGradeValue.D_Minus orderby grade.DepartmentCode, grade.CourseNumber select grade; List<Grade> gradeList = stage2Grade.ToList();

IndexOutOfRangeException

when you use a subscript value for a container than is < 0 or >= the capacity of the container


Kaugnay na mga set ng pag-aaral

Is the sentence Declarative, Interrogative, Imperative, or Exclamatory?

View Set

Algebraic and Geometric Properties for Proofs

View Set

APUSH Unit 7 College Board Review Questions

View Set

HESI Practice- Fundaments of Skill and Assessment

View Set