Fundamentals and Data Structes Flashcards
Structs
-are like classes but
-are value types
-stored in stack
-dont have parametress contructor
-dont support virual or abstract methods
-for smaller data
-dont support inheritance
-cannot have a null reference
-dont have a memory overhead
and classes are oposite!
Enums
An enum is a special “class” that represents a group of constants (unchangeable/read-only variables).
null coalescing operator
.It will return the value of its left-hand operand if it is not null. If it is null, then it will evaluate the right-hand operand and returns its result. Or if the left-hand operand evaluates to non-null, then it does not evaluate its right-hand operand.
Delegates
-holds the reference to a method
private delegate void OnClickDelegate()
-it is just a callback
-when I want to give a function as arugment to another function, i have to create it as a delegate
Lambda expression
() => {}
Mulitcast delegates
Mulitcast delegates are like a chain reaction of subscriptions
->
calling one method immediately call method that subscribes to it
LINQ
Language Integrated Query
retriving data from a data source
obtain a data source ->
create the query ->
execute the query
Async Code
public static async Task<T> GetData<T> (string ulr)</T></T>
- use try-catch
- using(var client = new HttpClient() )
- HttpResponseMessage response = await client.GetAsync(url)
- the use this condition to work with the result
if response.StatusCode == System.Net.HttpStatusCode.OK - make a string out of a response and then an object
var ResponseString = await response.Content.ReadAsStringAsync()
var ResponseObject = JSONConvert.DeserializeObject<T>(ResponseString)</T>
Action
actions has no return value, no return code
are always void
Func
an action that has a return value
Predicate
returns a bool
Func<T></T>
is a predefined delegate type for a method that returns some value of the type T.
public static string GetMessage() { return “Hello world”; }
Func<string> f = GetMessage;</string>
Func<TParameter, TOutput>- we decalre the given parameter and the output parameter
MUST HAVE RETURN TYPE
var
var- A var variable must be initialized at the time of declaration.
var can contain any type of data,
the compiler to figure out the variable type at compilation time.
IEnumerable vs List - What to Use? How do they work?
IEnumerable is read-only and List is not.
A class that implement IEnumerable allows you to use the foreach syntax.
Many types other than List<T> implement IEnumerable such as an ArrayList. So one advantage is you can pass different collection types to the same function.</T>
Action/Func vs Methods, what’s the point?
Action and Func are framework-provided Delegate types.
Delegates allow functions to be treated like variables, meaning that you can (among other things) pass them from method to method.