Week 2 Flashcards
What is a data type?
A type is a set of values and operations that are permitted on the values.
What are the two kinds of types?
A value type and a reference type.
Whats an example of a value type?
int x = 5
What’s an example of a reference type
string str = “hello”
Where is the actual data stored for a reference type?
In the heap.
Where is the reference stored for a reference type?
In the stack (value types are also found in the stack)
What are some examples of a value type?
int, double, long, char, bool, decimal
What are some examples of a reference type?
objects, strings, lists (any classes as well)
What’s a field?
a field stores data within a class
What’s a property?
Looks and acts like a field however it does not allocate memory for data.
ex:
class Demo
{ private int theRealValue; //a field
public int MyValue //a property
{
set{ theRealValue = value; }
get{ return theRealValue; }
}
}
What return type do set statements have?
a void return type
What return type do get statement have?
returns a value of the type of the property
What’s a method?
A block of code thar can be executed (or called).
What’s a constructor?
A kind of method, that is used to initialize the state of a class instance.
What is an access modifier?
The access modifier optionally specifies what other part of the program can access the member. (ex. public, private)
Where can private members be accessed?
Within the class in which they are declared.
Where can public members be accessed?
Throughout the entire program.
How do you instantiate a string, from a char array called “chars”?
string str = new string(chars);
Are strings immutable?
Yes
What does the StringBuilder class do?
Helps us produce strings while reducing the number of copies being made. It is mutable.
What namespace does the StringBuilder class use?
using System.Text;
What symbol is necessary to write an interpolated string.
$
OOP supports information hiding by using private fields, what is this called?
Encapsulation
What is concept of inheritance?
Types can be derived from other types, a type can be a subtype.