1/123
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
C#
developed by Microsoft in the early 2000s
C#
known for its OOP features and simplicity
using Directives
used to import namespaces, containing classes and other types used in the program
Namespaces
to organize code into logical groups and prevent naming conflicts
class declaration
classes are blueprints for creating objects encapsulating data and behavior
Main Method and Program Execution Flow
contains the program's main logic
Additional Methods and Class Members
a class can contain additional methods and class members defining the behavior of the program
Console.Write() and Console.WriteLine()
are used to output text, variables, and other data to the console
Console.WriteLine()
appends a new line character at the end of the output, moving the cursor to the next line
Format Specifiers
used within the string to indicate how variables should be formatted
Escape Sequences
special character combinations that represent characters that cannot be printed using the normal way of printing
\n or New Line
Moves the cursor to the beginning of the next line
\t or tab
Inserts a horizontal tab
\" Double Qoute
Inserts a double quote character
\' Single Qoute
Inserts a single quote character
\\ or Backslash
Inserts a backslash character
\b or Backspace
Moves the cursor back one position
\r or Carriage return
Moves the cursor to the beginning of the current line
{ and }
the function definition is placed inside these characters
Member Variables
These are places inside thr curly braces when defining a structure
Placeholders
used within output statements to specify the position and format of variable values. They are represented by format specifiers, enclosed in { and }
numeric position
Placeholders are identified by their (___________) within the curly braces
control the formatting
Format specifiers are used to (______________) of the displayed values
{0:d} or {0:D}
Format the 1st argument as a decimal (integer) number
{1:f} or {1:F}
Format the 2nd argument as a floating-point number
{2:c} or {2:C}
Format the 3rd argument as a currency value
{3:s} or {3:S}
Format the 4th argument as a string
Console.ReadLine()
is used to accept a string input from the user
int.Parse()
used to convert the input string into an integer
float.Parse()
used to convert the input string into a float
while loop
repeats a code block as long as specified condition is true----condition is evaluated BEFORE each iteration of the loop
do-while loop
allows you to repeat a code block at least once, and then continue repeating it as long as a specified condition is true------the condition is checked AFTER each iteration
for loop
allows you to repeat a code block a specific number of times----provides a concise and structured way to control loop iterations
syntax of while loop
while(condition) { //statements}
syntax of do-while loop
do{ //statements}while(condition);
syntax of for loop
for(initialization; condition; increment/decrement){ //statements}
initialization
initializes the loop control variable
condition
evaluated before each iteration
increment/ decrement
modifies the loop control variable; commonly used for incrementing and decrementing loop counter
Nested Loops
a powerful way to perform repetitive tasks that require multiple iterations
outer loop
for control and execution of inner loop
inner loop
iterations of the outer loop
break
prematurely terminates the execution of the loop
continue
used to skip the current iteration of a loop and move to the next iteration
array
a fundamental data structure in C# that allows you to store a COLLECTION of elements of the SAME type
Array traversal
process of accessing array elements one-by-one, allowing you to perform operation on individual elements or analyze the entire array
One-Dimensional Array
the simplest form of arrays and provides a convenient way to store and manipulate collections of data
arrayName.Length()
returns the value of the array's length/size
Two-Dimensional Array
Array containing multiple rows and columns, forming a grid-like structure
arrayName.GetLength(0);
returns the value of the array's length/size for rows
arrayName.GetLength(1);
returns the value of the array's length/size for columns
Function
encapsulates reusable codes / promotes the Don't Repeat Yourself (DRY) principle
return type, name, and parameters
A function is defined with a (_____), (_____), and (________) enclosed in parentheses
TRUE
TRUE OR FALSE: A function is called by specifying its name and passing the arguments if required
access_modifier
Specifies the accessibility of the function. It can be public, or private,or protected
return_type
Data type of the value the function returns. Use void if the function doesn't return any value
function_name
A unique name for the function, following the C# naming conventions
parameter_list
List of input parameters (if any) that the function expects. If there are no parameters, leave the parentheses empty
Function Body
Block of code inside the function where the task is performed
return value
If the function has a non-void return type, it must return a value of that type using the return statement
Actual Parameters
values passed on to the function when it is called
Formal Parameters
placeholders defined in the method declaration or definition
Passing by Value
C# passes parameters by value by default
TRUE
TRUE OR FALSE: Any changes made to the formal parameters within the method do NOT affect the original values of the actual parameters
Passing by Reference
allows methods to modify the original values of the actual parameters directly
ref
To pass by reference in C#, the (___) keyword is used
TRUE
TRUE OR FALSE: By passing a variable by reference to a method, any changes made to the formal parameters within the method will AFFECT the original values of the actual parameters
return Keyword
used to exit a method and provide a value to the caller
void
used if methods do not need to return any value
Recursive Functions
A function that CALLS ITSELF to solve a smaller instance of the same problem
Base Case
The simplest form of the problem that can be directly solved
Recursive Case
Where the function calls itself with a reduced version of the original problem until it reaches the base case
Structures
A fundamental concept in the C# programming language that allow you to define and manipulate COMPOSITE data types
Structures
They are used to group related data items of different types into a single unit
structure name ---- variable name
To create an instance, you use the (__________) followed by the (___________) and optionally initialize the members
dot (.) operator
used in accessing structure members
Classes
serve as essential blueprints for creating objects, which are instances of those classes
Fields
represent the STATE or CHARACTERISTICS of an object.
Methods
define the BEHAVIOR of the objects.
FALSE - Fields
TRUE OR FALSE: Methods They are defined within the class and store the object's data.
FALSE - Methods
TRUE OR FALSE: Fields allow you to perform actions or calculations related to the object's state
Methods
a block of code that performs a specific task and is designed to be reusable
Methods
typically associated with objects and are called on instances of classes.
Parameters
are accepted by methods, serves asits inputs.
Method Overloading
allows you to define multiple methods with the SAME NAME in the SAME CLASS, but with DIFFERENT PARAMETER lists.
Method Overloading
The methods must have either DIFFERENT TYPES or a DIFFERENT NUMBER of parameters.
Method Overriding
It occurs when a subclass provides a specific implementation for a method already defined by its superclass.
Method Overriding
both the method and method signature must be the same.
ACCESS MODIFIERS
determine the visibility and accessibility of methods.
public
The method is accessible from any class.
protected
The method is accessible within its class, subclasses, and other classes in the same assembly.
internal
The method is accessible within its class and other classes in the same assembly (assembly-private).
private
The method is only accessible within its class.
constructor
a special method used for initial values or perform setup tasks for the object.
constructor
They have the same name as the class they belong to and automatically called when an object of the class is created.
automatically ---- new
The constructor is called (____) when you create an object using the (___) keyword.
class
The constructor's name must be the same as the (___) name.
default constructor
C# automatically provides a (____________) if a constructor is not explicitly defined.
PARAMETERIZED CONSTRUCTOR
These are constructors accepting parameters.
CONSTRUCTOR OVERLOADING
This allows you to define multiple constructors within the same class, each taking a different set of parameters.