C# study - Sheet1 Flashcards
In .NET, you don’t immediately create operating system-specific native code. Instead, you compile into Common Intermediate Language code.
T
What is the term for the .Net method of freeing up unused memory?
Garbage Collection
C# is a typesafe language.
T
Console applications are simple command-line applications
T
What type of language is C#
block-structured language
What are comments for?
Adding descriptive text to code.
Name four integer types.
byte, short, int, long
A string is a sequence of numbers
F
Give an example of a camelcase variable name.
firstName
What are the allowed value of Boolean?
True or False
What are the 3 categories that operators can be divided into
Unary, Binary, Ternary
Variables are chunks of data that have a name and a type.
T
What are the three branching techniques available in C#?
Ternary, If, Switch
In a switch statement, it is legal to execute more than one case.
T
Looping refers to the repeated execution of statements.
T
How do implicit and explicit conversions differ?
Implicit: conversion is possible in all circumstances, and the compiler can do it. Explicit: conversion is possible only in certain circumstances.
Structs can’t have different data types in them
F
What is the term for variable in a struct?
data members
What is a struct?
data structures that are composed of several pieces of data, possibly of different types.
How many base types are in an array?
1
How do you declare an array?
[] ;
What do foreach loops enable?
Enables you to address each element in an array.
A jagged array is an array of arrays of different lengths.
T
When a function returns a value, you have to specify the type in the function declaration, and use the return keyword at the end of the function’s execution.
T
Passing a parameter by reference means the referenced variable will be used each time a function is run rather than using a constant number.
T
Global variables can have a scope of more than one function?
T
A delegate is a type that enables you to store references to functions.
T
What is the main advantage of using Release builds?
Release builds run faster.
When in debug mode in Visual Studio the step into command will execute and move to the next statement to be executed.
T
Error handling is the term for all techniques involving finding and correcting errors.
T
Nondefault constructors are constructors that include starting parameters
T
Default constructors are parameter-less methods (that don’t return anything).
T
Who are static members shared with?
They are shared between instances of a class.
Interfaces can exiswt on their own.
F
What is an interface?
A collection of private instance methods and properties that are grouped together.
What does the term inheritance mean in OOP?
It wil have all the members of the class from which it inherits.
In C#, all classes derive from the base class Parent at the root of the class.
T
What does polymorphism allow?
All objects instantiated from a derived class can be treated as if they were instances of a parent class.
What is containment?
One class contains another.
What is the base class in C#?
System
Abstract classes can posses both abstract members and non-abstract members.
T
Abstract classes can contain members that can be inherited by a derived class, while interfaces cannot.
T
When you assign an object to a variable, you are actually assigning that variable with a pointer to the object to which it refers.
T
A full copy is referred to as a deep copy.
T
Within a class definition, all members have the same accessibility levels.
F
Public members are accessible from any code
T
Protected Members are accessible only from code that is part of either the class or a derived class.
T
A Field is like a variable.
T
A method is like a function.
T
Fields, methods, and properties can also be declared using the keyword global, which means they are static members owned by the class.
F
Where can you access private members from?
Code that is part of the class.
Which keyword’s members are accessible only from code within the assembly (project) where they are defined
Internal
What are the four class definition modifiers for accessibility?
public, private, internal, protected
If override is used, then sealed can also be used to specify that no further modifications can be made to this method in derived classes
T
Accessors are defined using get and set keywords respectively, and can be used to control the access level of the property.
T
What does the override method do?
overrides a base class method.
Properties contain a type name, a property name, and one or both what kind of blocks?
Get / Set
You must use an accessor to make a property useful.
T
Properties use the same keywords as fields and methods.
T
What does the keyword “value” refer to?
Equates to a value of the same type as the property.
Refactoring is modifying your code using a tool, rather than by hand.
T
The only limitation of automatic properties is that they must include both a Get and Set acessor.
T
When you inherit a non-abstract member from a base class, you also inherit an implementation.
T
Why properties are the preferred way to access the state of an object
They shield external code from the implementation of data storage within the object.
With an automatic property, you declare what?
A property with a simplified sytax.
When a base implementation is hidden, how can you still access it?
Use the base keyword.
You can define types such as classes in namespaces, and you can also define them inside other classes.
T
The most useful function of the base keyword is the capability to pass a reference to the current object instance to a method
F
Like base, this refers to an object instance, although it is a future object instance.
F
What does the “this” keyword referto?
an object instance
What is the keyword this used for in C#?
the capability to pass a reference to the current object instance to a method.
Interface members are defined like functions.
F - class members
Interfaces can contain code bodies.
F - they can’t
Why would you want to use the “new” keyword in defining interface members?
If you want to hide members inherited from base interfaces.
A class that implements an interface must contain implementations for all members of that interface,
T
Interface values specify how the property data should be stored.
F
It is possible to implement interface members using the keyword virtual or abstract but no static or const.
T
Interface members cannot be implemented explicitly by a class.
F
It is possible to add a get block to a property in a class in which the interface defining that property only contains a set block, and vice versa.
T
What is the code that allows fields to expand and contract?
region and #endregion
What is one technique to avoid confusing and cluttered code as described in chapter 10?
Code outlining.
Partial methods are defined in one partial class definition without a method body, and implemented in another partial class definition.
T
Methods can be split using partial keyword?
T
What is a partial class definition used for?
put the fields, properties, and constructor in one file, and the method in another.
What is the keyword that allows methods to be split between multiple files.
partial
Partial methods can be static.
T
What happens when you complie code that contains a partial method definition without an implementaiton?
thecompler removes the method entirely.
Properties and methods can be defined as abstract or virtual in base classes to define inheritance
T
A class that implements an interface must implement all of the members defi ned by that interface as private
F
Partial methods have certain restrictions, including no return value or out parameters.
T
Properties and methods can be defined as ______ or ______ in base classes to define inheritance.
abstract or virtual.
Which member has an accessibility, return type, name, and parameters?
Field
Unlike arrays, collections can control access to the objects they contain, search and sort, and more.
T
What do collections enable you to maintain?
groups of objects
IList Provides a list of items for a collection along with the capabilities for accessing these items, and some other basic capabilities related to lists of items
T
IDictionary — Similar to IList, but provides a list of items accessible via a key value, rather than an index
T
Arrays in C# are implemented as instances of the System.Array class and are just one type of what are known as collection classes.
T
The System.Array class supports some of the more advanced features of IList, and it represents a list of items by using a fixed size.
T
Collection classes in general are used for maintaining lists of objects.
T
Custom collection classes can be strongly typed.
T
Much of the functionality for collection classes comes through implementing interfaces from the System.Interfaces namespace.
T
System.Array is just one example of a collection class in C#.
T
What does ienumerable do?
Provides the capability to loop through items in a collection.
What does icollection do?
Provides the capability to obtain the number of items in a collection and copy them into a simple array type.
Collections contain a constructor that will double the capacity automatically if the number of items in the collection ever exceeds the initial value.
T
With arrays of reference types, simply initializing the array with a size initializes the items it contains.
F
You can derive a collection from a class, such as System.Collections.CollectionsBase.
T
What is the recommended way to derive a collection you create from a class as described in our text?
Using the Systm.Collections.CollectionBase
Two methods provided by the CollectionBase interface are Clear() and RemoveAt().
T
What is a special kind of property that you can add to a class to provide array-like access
indexer
What does an indexer property do?
Provides array-like access
What does CollectionBase interface do in C#?
Provides 2 protected properties that enable access to the stored objects themselves.
The this keyword is used along with parameters in round brackets
T
As with indexed collections, there is a base class you can use to simplify implementation of the IDictionary interface: DictionaryBase.
T
How does IDictionary differ from IList?
RemoveAt() is not included.
The Remove member Takes a key parameter and an object reference.
F
One difference between collections based on DictionaryBase and collections based on CollectionBase is that foreach works differently.
T
The IEnumberable interface allows the use of foreach loops.
T
What does the add member do?
It takes two parameters and stores them together.
The IEnumerable interface enables you to use what kind of loop?
foreach
To iterate over a class, use a method called what?
GetEnumerator with IEnumerator as the return type.
To iterate over a class member, such as a method, use what?
IEnumerable
A good definition of an iterator is a block of code that supplies all the values to be used in a foreach block in sequence.
T
What is a good definition of an iterator?
A block of code that supplies all the values to be used in a foreach block in sequence.
Within an iterator block, you select the values to be used in the foreach loop by using which keyword?
yeild
It is impossible to interrupt the return of information to a foreach loop.
F
Value comparisons determine what an object is or what it inherits from.
F
What are two types of comparisons between objects?
Type and Value
What is boxing (in terms of C#, not the sport)?
The act of converting a value type into the System.Object type or to an interface type that is implemented by the value type.
If is a class type, then the result is true if is of that type, if it inherits from that type, or if it can be boxed into that type.
T
If is a value type, then the result is true if is of that type or it is a type that can be unboxed into that type.
T
The “is” operator enables you to check whether an object either is or CAN BE CONVERTED into a given type.
T
What is the syntax for the “is” operator?
is
What does the is operator enable?
You to check whether an object is or can be converted into a given type.
Class overloading enables you to use standard operators, such as +, >, and so on with classes that you design.
F
What does operator overloading enable you to do?
You to use standard o[erators with classes that you design.
Why is operator overloading useful?
you can perform whatever processing you want in the implementation of the operator overload.
Operator overloads look much like standard static method declarations.
T
If you overload the true and false operators, then you can use classes in Boolean expressions, such as if(op1){}.
T
Assignment operator cannot be overloaded
T
What parameter does equals() use
object
Where is Icomparable implemented
In the class of the object to be compared.
What does the IComparer interface allow?
Allows comparisons between that object and another object.
When using Comparer, the types don’t have to be comparable.
F
Strings are processed in case-sensitive way.
T
What does the “as” operator convert?
Converts a type into a specified reference type.
You can use the GetType() method to obtain the type of an object, or the typeof() operator to get the type of a class.
T
To iterate over a class, implement a method called GetEnumerator() with a return type of IEnumerable.
T
What are collections
Classes that can contain instances of other classes.