- When you need to define an object type's characteristics, use an interface. When you need to define an object type's capabilities, use an abstract class.
- Interfaces are a legacy of older versions of C#, and are interchangeable with the newer abstract class feature.
- When you need a list of capabilities and data that are classes-agnostic, use an interface. When you need a certain object type to share characteristics, use an abstract class.
- You should use both an interface and an abstract class when defining any complex object.
- Delegates are not supported in the current version of C#
- They cannot be used as callbacks.
- Only variables can be passed to delegates as parameters.
- They can be chained together.
- reactive
- inherited callback
- task-based
- callback-based
- .
var type = typeof(SomeType);
var attribute = type.GetCustomAttribute<SomeAttribute>();
- .
var typeof(MyPresentationModel).Should().BeDecoratedWith<SomeAttribute>();
- .
Attribute.GetCustomAttribute, typeof(SubControllerActionToViewDataAttribute)
- .
Attribute.GetCustomAttribute(typeof(ExampleController), typeof(SubControllerActionToViewDataAttribute))
- Variables passed to out specify that the parameter is an output parameter, while ref specifies that a variable may be passed to a function without being initialized.
- Variables passed to ref can be passed to a function without being initialized, while out specifies that the value is a reference value that can be changed inside the calling method.
- Variables passed to out can be passed to a function without being initialized, while ref specifies that the value is a reference value that can be changed inside the calling method.
- Variables passed to ref specify that the parameter is an output parameter, while out specifies that a variable may be passed to a function without being initialized.
- reflection
- serialization
- abstraction
- dependency injection
```
private static object objA;
private static object objB;
private static void performTaskA()
{
lock (obj)
{
Thread.Sleep(1000);
lock (objA) { }
}
}
private static void PerformTaskB()
{
lock (objA)
{
lock (objB) { }
}
}
```
- a private class that uses multithreading
- multithread coding
- thread mismanagement
- a potential deadlock
- Anonymous types don't have type names
- Anonymous types can only be static
- Anonymous types can be used only in struts
- Anonymous types don't work with LINQ.
- when you need a jagged collection structure
- when you need to store values of the same type
- when you need to store key-value pairs rather than single values
- when you need an ordered, searchable list
- The .Equals method compares reference identities while the == compares contents.
- The .Equals method compares primitive values while == compares all values.
- The .Equals method compares contents while == compares references reference identity.
- The .Equals method compares reference type while == compares primitive value types.
- when you try to instantiate two objects at the same time in the same class or struct
- when you are trying to execute an action after a user event is registered
- when simultaneous instructions are waiting on each other to finish before executing
- when you try to execute a series of events simultaneously on multiple threads
- It allows access to asynchronous methods in the C# API
- It allows thread pooling and synchronous processes in static classes.
- It allows the await keyword to be used in a method
- It allows access to synchronous methods in the C# API
- a class or struct, including its variables and functions
- a primitive data type that can be created only at compile time
- a value type that can be used only with an abstract class
- an instance of a class or struct that includes fields, properties, and/or methods
- var<T> userData = new <T> { name = "John", age = 32 };
- var userData = new { name = "John", age = 32 };
- AType userData = new AType { name = "John", age = 32 };
- Anonymous userData = new Anonymous { name = "John", age = 32 };
public void userInput(string charParamters) { }
- nothing
- a Boolean
- a string variable
- an integer
`
string[] employees = { "Joe", "Bob", "Carol", "Alice", "Will" };
IEnumerable<string> employeeQuery = from person in employees
orderby person
select person;
foreach(string employee in employeeQuery)
{
Console.WriteLine(employee);
}
`
- ascending
- unordered
- descending
- first in, first out
- Namespaces
- LINQ
- Type Aliasing
- Assemblies
- // - Single Line / - Multiline
- // Multiline /_ Single Line _/
- //* Multiline / Single Line
- // Single Line /_ Multiline _/
- Make it public
- Make it static
- Make it private
- Make it virtual
- public int Age { get - set }
- public int Age: get set;
- public int Age (get, set );
- public int Age { get; set; }
- a class that is denoted by the class keyword (can be seen and used by any other class in the system--thus it is by default public)
- something denoted by the abstract keyword and used system wide; if you want any program to create an object of a class you use the abstract class
- a class that is denoted by the virtual keyword
- a class that can be used only as base class
- The thread is destroyed and memory is freed up.
- The thread runs in loop until the next assignment.
- The thread goes inactive in the background and waits for garbage collection.
- The thread returns to the pool for reuse.
- a second base class
- a revised class
- a derived class
- a parent class
- hide built-in operatores when necessary
- add methods to be interpreted by the compiler at runtime
- define how enums and other primitive value types work within the rest of the application
- define custom functionality for common operators like addition and equality
- to delete duplicate data
- to bind namespaces and assemblies
- to query and transform data
- to connect assemblies
- public List contacts = new List();
- public List(string names) contacts = new List(string names)();
- var contacts = new List();
- var contacts = new List(string);
- Throw clauses fire only at runtime, while throw exceptions can fire at any time.
- Throw exceptions overwrite the stack trace, while throw clauses retain the stack information.
- Throw clauses overwrite the stack trace, while throw exceptions retain the stack information.
- Throw exceptions fire only at runtime, while throw clauses can fire during compile time.
Q28. When an asynchronous method is executed, the code runs but nothing happens other than a compiler warning. What is most likely causing the method to not return anything?
- The return yield statement is missing at the end of the method.
- The method is missing an await keyword in its body.
- The wait keyword is missing from the end of the method.
- The yield keyword is missing from the method.
- system actions that communicate directly with the compiler at runtime
- actions that execute when the code compiles, generating logs and test output
- actions that generate notifications, which are sent to their registered listeners** <= Correct
- user-only methods that send data to the application's back end
- unordered collections of numerc values
- key-value pairs of any C# supported type
- class and struct instances
- multiple variables, or collections, of the same type
enum AppState { OffLine, Loading, Ready }
- string currentState = (string)AppState.Loading;
- string currentState = AppState.Loading.integralVal;
- int currentState = AppState.Loading.rawValue;
- int currentState = (int)AppState.Loading;
- d
- \a
- \b
- \w
```
public interface INameble
{
string FirstName { get; set; }
string LastName { get; }
}
```
- Both the FirstName and LastName properties need to be implemented.
- Neither, they are both optional.
- Only the LastName property needs to be implemented.
- Only the FirstName property needs to be implemented.
Q34. You're dealing with multiple assemblies in your program, but are worried about memory allocation. At what point in the program life cycle are assemblies loaded into memory?
- at runtime
- at compile time
- only when required
- only when programmatically loaded
- A regular expression is a C# tool used to parse HTML
- A regular expression is a special text string for describing a search patters.
- A regular expression allows a variable to be passed by reference.
- A regular expression allows a class to conform to the Equatable protocol.
- To define behaviours of the class
- To hold information and data contained in the class object
- To communicate between classes and object
- To store the class definition value
- to increase code performance
- all of these answers
- when code reuse is a priority
- when type safety is important
public delegate void AuthCallback(bool validUser); public static AuthCallback loginCallback : Login; public static void Login() { Console.WriteLine("Valid user!"); } public static void Main(string[] args) { loginCallback(true); }
- Login successful...
- Valid user!
- an error, because the method signature of Login doesn't match the delegate //It will throw an error because you cant apply Inheritance to methods that way.
- Login successful... Valid user!
- public class User
- abstract User {}
- sealed class User
- private sealed class User
-
public delegate void ResultCallback<(int) responseCode>
; -
public delegate ResultCallback(int responseCode)
; -
public delegate void ResultCallback(int responseCode)
; -
public void delegate ResultCallback<int responseCode>
;
- non-static classes need to be initialized before use, while static classes do not reference
- non-static classes are accessible only from an interface while static classes are accessible from anywhere
- non-static classes need to initialize all class members at runtime, while static classes do not
- non-static classes do not need to be initialized while static classes do
public int age="28"
- type safety
- single inheritance
- dependency injection
- multiple inheritance
public class User {}
- mark the User class with the DeserializableAttribute
- Declare it as public serializable class User {}
- Mark it with the SerializableAttribute // [Serializable] public class User {}
- Declare it as private serializable class User{}
- public delegate ResultCallback(int responseCode)
- public delegate void ResultCallback<(int) responseCode>;
- public void delegate ResultCallback;
- public delegate void ResultCallback(int responseCode);
- non-static methods always need to have a void return type
- non-static methods do not have access to static member variables
- static methods do not have to instantiate an instance of the class to call the method
- static methods always have to be public
Q46. What is the correct way to write an event named apiResult based on a delegate named ResultCallback?
- public void event ResultCallback apiResult;
- public event ResultCallback(() -> apiResult);
- public event void ResultCallback
- public event ResultCallback apiResult;
- if there is an error, it won't execute at all
- between the try and catch blocks
- after the try and catch blocks
- when the finally block overrides the catch block and executes in its place
- public static string IsvalidName(this string i, string value) {}
- public static void IsvalidName(this string i, string value) {}
- public string IsvalidName(this string i, string value) {}
- public void IsvalidName(this string i, string value) {}