Documentation officielle : Délégués
Documentation officielle : Modèle de programmation asynchrone basé sur les tâches réponse correcte --> 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))
Documentation officielle : Réflexion
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) { }
}
}
Documentation officielle : Interblocages et conditions de course
Documentation officielle : Types anonymes
Documentation officielle : Classe Dictionary<TKey,TValue>
== compare le contenu.== compare toutes les valeurs.== compare l’identité de référence.== compare les types de valeur primitifsDocumentation officielle : Interblocages et conditions de course
Documentation officielle : async
Documentation officielle : Objets
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 };Documentation officielle : Types anonymes
public void userInput(string charParameters) { }
Documentation officielle : void
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 : Opérateur LINQ OrderBy
Documentation officielle : Vue d’ensemble de Language Integrated Query (LINQ)
/_/ - Une ligne
/_ - Multiligne// Multiligne
/_ Une ligne _///\* Multiligne
/ Une ligne// Une ligne
/* Multiligne */Documentation officielle : Utilisation des propriétés
Documentation officielle : Classes et membres de classe abstraits et sealed
Documentation officielle : Caractéristiques du pool de threads
Documentation officielle : Héritage
Documentation officielle : Surcharge d’opérateur
Documentation officielle : Vue d’ensemble de Language Integrated Query (LINQ)
[Documentation officielle : Classe List
Documentation officielle : Démarrer les tâches de manière concurrente
Documentation officielle : Introduction aux événements
Documentation officielle : Tableaux
enum AppState { OffLine, Loading, Ready }
Documentation officielle : Types d’énumération
public interface INameable
{
string FirstName { get; set; }
string LastName { get; }
}
Documentation officielle : interface
Documentation officielle : Introduction aux classes
Documentation officielle : Classes et méthodes génériques
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);
}
Documentation officielle : Classes et membres de classe abstraits et sealed
public int age="28"
c-sharpcorner : Sécurité des types dans .NET
public class User {}
DeserializableAttribute.public serializable class User {}.SerializableAttribute.private serializable class User {}.Documentation officielle : Classe SerializableAttribute
Documentation officielle : Délégués
Documentation officielle : Membres statiques
Documentation officielle : Introduction aux événements
Documentation officielle : try-catch
Documentation officielle : Héritage de classe
Documentation officielle : 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; }
}
Documentation officielle : Utilisation des propriétés
Documentation officielle : Classe ThreadPool
Documentation officielle : Sérialisation
Documentation officielle : Délégués
Documentation officielle : Exceptions
Documentation officielle : Enum
break et continue ?break est utilisé pour sortir de plusieurs instructions d’itération, tandis que continue ne peut sortir que des blocs de code qui ont des itérations simples.break sort littéralement d’une instruction de flux de contrôle, tandis que continue ignore le reste de l’instruction de contrôle ou de l’itération et commence la suivante.break sort littéralement du code de flux de contrôle actuel et l’arrête complètement, tandis que continue continue d’exécuter le code après qu’une exception soit levée.break sort d’une itération puis procède avec le reste du code de flux de contrôle, tandis que continue arrête le code en cours d’exécution complètement.Documentation officielle : Instructions de saut
get public et un set privé ?public int userID <get, set>;public int userID [get, private set];public int userID { get; private set; }public int userID = { public get, private set };Documentation officielle : Propriétés
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 forDocumentation officielle : race conditions
A string cannot be nullable.string? myVariablestring myVariable = nullstring(null) myVariableDocumentation officielle : types de valeur nullable
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]Explication : Vous pouvez faire cela en C#. Cependant, aucune des réponses ci-dessus n’est correcte. Vous pouvez accéder aux deux derniers éléments en utilisant People[^2..]. Veuillez consulter issue #3354 pour plus d’informations.
Voir aussi : Documentation officielle : 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.Documentation officielle : Threads
private string LastName;
Documentation officielle : Niveaux d’accessibilité
string[] partyInvites = new string[10];string[][] partyInvites = new string[10][];string[][] partyInvites = new string[10]();string <[]> partyInvites = new string <[10]>;Documentation officielle : Tableaux en escalier
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.Documentation officielle : Méthodes (Guide de programmation C#)
ArgumentNullValueInvalidFormatFoundExceptionIndexOutOfPocketArgumentNullExceptionDocumentation officielle : Classe ArgumentNullException
Documentation officielle : Interfaces (Guide de programmation C#)
finally dans une instruction try-catch-finally C# ?finally est utilisé pour gérer les exceptions.finally est utilisé pour définir la logique principale de l’instruction try-catch.finally est optionnel et n’est pas requis dans les instructions try-catch.finally est utilisé pour s’assurer qu’un certain code est exécuté indépendamment de savoir si une exception se produit.Documentation officielle : try-catch (Référence C#)
Documentation officielle : Classe Dictionary<TKey, TValue>
[Référence] : https://www.gkseries.com/c-sharp-programming/multiple-choice-questions-and-answers
[Référence] : https://www.gkseries.com/c-sharp-programming/multiple-choice-questions-and-answers