Official documentation: Delegates
Official documentation: Task asynchronous programming model resposta correta --> var contacts = new List
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))
Official documentation: Reflection
private static object objA;
private static object objB;
private static void performTaskA()
{
lock (objB)
{
Thread.Sleep(1000);
lock (objA) { }
}
}
private static void PerformTaskB()
{
lock (objA)
{
lock (objB) { }
}
}
Official documentation: Deadlocks and race conditions
Official documentation: Anonymous Types
Official documentation: Dictionary<TKey,TValue> Class
== compares contents.== compares all values.== compares reference identity.== compares primitive value typesOfficial documentation: Deadlocks and race conditions
Official documentation: Objects
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<T> userData = new Anonymous<T> { name = "John", age = 32 };Official documentation: Anonymous Types
public void userInput(string charParameters) { }
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);
}
dotnetpattern: LINQ OrderBy Operator
Official documentation: Language Integrated Query (LINQ) Overview
/_/ - Single Line
/_ - Multiline// Multiline
/_ Single Line _///\* Multiline
/ Single Line// Single Line
/* Multiline */Official documentation: Using Properties
Official documentation: Abstract and Sealed Classes and Class Members
Official documentation: Thread pool characteristics
Official documentation: Inheritance
Official documentation: Operator overloading
Official documentation: Language Integrated Query (LINQ) Overview
[Official documentation: List
Official documentation: Starting tasks concurrently
Official documentation: Introduction to events
Official documentation: Arrays
enum AppState { OffLine, Loading, Ready }
Official documentation: Enumeration types
public interface INameable
{
string FirstName { get; set; }
string LastName { get; }
}
Official documentation: interface
Official documentation: Introduction to classes
Official documentation: Generic classes and methods
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);
}
Official documentation: Abstract and Sealed Classes and Class Members
public int age="28"
c-sharpcorner: Type Safety in .NET
public class User {}
DeserializableAttribute.public serializable class User {}.SerializableAttribute attribute.private serializable class User {}.Official documentation: SerializableAttribute Class
Official documentation: Delegates
Official documentation: Static Members
Official documentation: Introduction to events
Official documentation: try-catch
Official documentation: Class inheritance
Official documentation: namespace
private int _password;
pubic int Password = { get; set; }
private int _password;
public int Password = _password;
private int _password;
public int Password
{
get -> _password;
set-> _password = value;
}
private int _password;
public int Password
{
get { return _password; }
set { _password = value; }
}
Official documentation: Using Properties
Official documentation: ThreadPool Class
Official documentation: Serialization
Official documentation: Delegates
Official documentation: Exceptions
break and continue keywords?break keyword is used to break out of multiple iteration statements, while continue can only break out of code blocks that have single iterations.break keyword literally breaks out of a control flow statement, while continue ignores the rest of the control statement or iteration and starts the next one.break keyword literally breaks out of the current control flow code and stops it dead, while continue keeps executing the code after an exception is thrown.break keyword jumps out of an iteration and then proceeds with the rest of the control flow code, while continue stops the executing code dead.Official documentation: Jump statements
get and private set?public int userID <get, set>;public int userID [get, private set];public int userID { get; private set; }public int userID = { public get, private set };Official documentation: Properties
Overriding virtual methods in a derived class is mandatory.Overriding virtual methods in a derived class is not possible.Virtual methods always need a default implementation.Virtual methods cannot have a default implementation.resource overloadthread jumpingdeadlock and race conditionsnothing, since this is what threading is forOfficial documentation: race conditions
A string cannot be nullable.string? myVariablestring myVariable = nullstring(null) myVariableOfficial documentation: nullable value types
No, you can declare an out in the parameter list.No, Out variables are no longer part of C#.You must declare it if it is a primitive type.Yes.People[..^2]You cannot do this in C#.People[..^3]People[^2]Explain: You can do this in C#. However, none of the above answers are correct. You can access the last two items by using People[^2..]. Please see issue #3354 for more information.
See also: Official Documentation: Ranges
at compile timeafter runtimeat runtimeafter compile timeC-sharpcorner: Anonymous Types
Thread multitasking allows code to be executed concurrentlyThread multitasking allows code to be executed only when handling a user event.Thread multitasking blocks code from being executed simultaneously to guard memory.Thread multitasking adds single-threaded code blocks together.Official Documentation: Threads
private string LastName;
Official Documentation: Accessibility Levels
string[] partyInvites = new string[10];string[][] partyInvites = new string[10][];string[][] partyInvites = new string[10]();string <[]> partyInvites = new string <[10]>;Official Documentation: Jagged Arrays
void MyFunction()
{
{
int a = 10;
int b = 20;
int c = a + b;
}
Console.WriteLine(c);
}
public class PremiumUser sub User {}public class PremiumUser: User {}public class PremiumUser -> sub User {}public class User: PremiumUser {}static InputManager.DebugString();InputManager().DebugString;new InputManager().DebugString();InputManager.DebugString();public string? nickname
a special called automatically whenever an object is created or updatedan implicit method called automatically when thread pools are processed concurrentlyan explicit method called automatically when the compiler starts runninga special method called automatically whenever an object is deleted or destroyedtypealias CustomInt = System.Int32;var<T> CustomInt = Int32;using CustomInt = System.Int32;type CustomInt = System<Int32>;an object of pass by reference typea value type that cannot hold constantsset of named integral constantsan object of pass-by-value typeto declare a member variable that cannot be calculated at runtimeto declare a field whose value can be assigned only before the constructor exitsto declare a static variable that must be set at compile timeto declare a static variable that must be set at runtimeMethods store variables.Methods are actions that an object can takeA method can be used only once per C# file.A method determines the state of a given property.Official documentation: Methods (C# Programming Guide)
ArgumentNullValueInvalidFormatFoundExceptionIndexOutOfPocketArgumentNullExceptionOfficial documentation: ArgumentNullException Class
Official Documentation: Interfaces (C# Programming Guide)
finally block in a C# try-catch-finally statement?finally block is used to handle exceptions.finally block is used to define the main logic of the try-catch statement.finally block is optional and not required in try-catch statements.finally block is used to ensure that certain code is executed regardless of whether an exception occurs.Official Documentation: try-catch (C# Reference)
Official Documentation: Dictionary<TKey, TValue> Class