C# Terms Flashcards
C# terms from week 1 & 2 of Centriq's C# Fundamentals class
**VARIABLE **
- a storage container which holds the data for the runtime of the program. - must be of “type something” i.e. int, string, bool, decimal, etc.
DATA TYPE
- all variables must be of “type” something in .Net…
- data type specifies the range and/or type of information a variable can hold, and methods available to it.
Examples: byte, short, int, long, float, double, decimal, bool, char, string.
BASIC DATA TYPE
byte, short, int, long, float, decimal,
double, bool, char, string.
DECLARE
The 1st time you create
(by naming & giving a data type to) a variable.
Example: int x;
INITIALIZE
the first time you assign value to a variable.
Example: int y = 5; OR x = 20;
ASSIGN VALUE
- setting a value to be held by a variable.
- does not have to be the “first time” a value has been assigned to the variable.
Example: int z = 1; OR y = 109;
an object
An actual instance that has been created from a class.
Example: bool isTrue = true; int lamps = 99; Random nbrGenerator = new Random(); DateTime thisDay = new DateTime (2010, 1, 27)
…where isTrue, lamps, nbrGenerator and this Day are all objects of their respective classes (Bool, Int32, Random, DateTime). Similar to variable and instance.
Object
The Object class is from the Framework Class Library (FCL); it is the top-tier class from which all other classes inherit.
********** extra info… - this means that at a base level we can say that all objects (instances of any class) also inherit from the base class Object. So no matter what class an object is an instance of, it is also an instance of the Object class and inherits certain properties and methods (like ToString());
CLASS
- sometimes called a blueprint…from which you make real houses (instances/objects)
- or a template from which you make real things (instances/objects).
- A class ~ data type… A class can essentially provide the definition to create variables of that data type.
- Classes are a collection of types of information and specific behaviors that are modeled after real-world things you will need to work with in your program (employees, volunteers, shopping carts, products, customers, etc).
By making a class to hold information about any given employee, and by including behaviors that any employee should be able to do, you can instantiate (create an instance of) the Employee class you made – and know that every employee will be able to store certain information about itself (firstName, lastName, dateOfHire, etc) and be able to perform certain behaviors (ClockIn(), ClockOut(), ScheduleMeeting()) etc…
INSTANCE (OF SOMETHING)
Usually stated “an instance of X” where X is a class. Similar to variable and object.
INSTANTIATE
to create an object/instance from some class.
METHOD
the “verbs” of our language, methods perform some action or block of code when called. The Main() method runs automatically when a program is launched and is called the “entry point of the program”.
STATIC METHOD
- opposite of an “instance method”
- a static method is called w/o creating an instance of the class in which the method is declared.
Examples: Console.WriteLine(), Main(), or DisplayNow() below (note void in declaration, and no instance of MethodsEx1 class needed to call it from Main().
INSTANCE METHOD
The default access modifier for a method, an instance method requires you to have an instance of the class it’s created inside in order to call it. You won’t declare a method as an instance method unless you plan to make objects from the class in which you’re declaring the method. Example: Note the source code file (ClassesIntro.cs) contains a new class for Dog, and Dog has its own methods. If you want individual Dog objects to be able to perform that method, you’ll need to make them instance methods. You can leave off the word “instance” in your Bark() method because the default access modifier defaults to instance. You’ll need a Dog object before you can call it from Main():
RETURN TYPE
Specified when declaring a method. Designates what data, if any, should be “returned” as a result of running the method. A method that just runs a Console.WriteLine() method that displays a result of calculations is not “returned data”. If no “data will be returned”, the return type is “void”. If your return type is not void, it should specify a data type of the data you will return(string, int, bool, Random, DateTime, etc). ALSO, you will need a return statement at the end that lets you choose what actual data to return (its data type must match the return type you specified). Examples below show a method declared with a void data type (ShowFinedPaycheck()) and one that returns a decimal (ReturnPaycheckAmount());