官方文档:基于任务的异步编程模型 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))
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) { }
}
}
==比较内容。==比较所有值。==比较引用身份。==比较原始值类型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 };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);
}
/_/ - Single Line
/_ - Multiline// Multiline
/_ Single Line _///\* Multiline
/ Single Line// Single Line
/* Multiline */[官方文档:List
enum AppState { OffLine, Loading, Ready }
public interface INameable
{
string FirstName { get; set; }
string LastName { get; }
}
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);
}
public int age="28"
public class User {}
DeserializableAttribute标记User类。public serializable class User {}。SerializableAttribute属性标记User类。private serializable class User {}。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; }
}
break和continue关键字之间的区别是什么?break关键字用于跳出多个迭代语句,而continue只能跳出具有单个迭代的代码块。break关键字字面上跳出控制流语句,而continue忽略控制语句或迭代的其余部分并开始下一个。break关键字字面上跳出当前控制流代码并停止它,而continue在抛出异常后继续执行代码。break关键字跳出迭代然后继续执行其余的控制流代码,而continue停止执行代码。get和私有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 };在派生类中重写虚拟方法是强制性的。在派生类中重写虚拟方法是不可能的。虚拟方法总是需要默认实现。虚拟方法不能有默认实现。资源过载线程跳跃死锁和竞争条件什么都没有,因为这就是线程的用途字符串不能为null。string? myVariablestring myVariable = nullstring(null) myVariable不需要,你可以在参数列表中声明out。不需要,Out变量不再是C#的一部分。如果是原始类型,你必须声明它。是的。People[..^2]在C#中你不能这样做。People[..^3]People[^2]解释:你可以在C#中这样做。但是,上述答案都不正确。你可以通过使用People[^2..]来访问最后两个项目。更多信息请参见issue #3354。
另见:官方文档:范围
在编译时在运行时之后在运行时在编译时之后线程多任务允许代码并发执行线程多任务允许代码仅在处理用户事件时执行。线程多任务阻止代码同时执行以保护内存。线程多任务将单线程代码块加在一起。private string LastName;
string[] partyInvites = new string[10];string[][] partyInvites = new string[10][];string[][] partyInvites = new string[10]();string <[]> partyInvites = new string <[10]>;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
在对象创建或更新时自动调用的特殊方法在线程池并发处理时自动调用的隐式方法在编译器开始运行时自动调用的显式方法在对象被删除或销毁时自动调用的特殊方法typealias CustomInt = System.Int32;var<T> CustomInt = Int32;using CustomInt = System.Int32;type CustomInt = System<Int32>;按引用传递类型的对象不能保存常量的值类型命名整数常量的集合按值传递类型的对象声明一个在运行时无法计算的成员变量声明一个只能在构造函数退出前赋值的字段声明一个必须在编译时设置的静态变量声明一个必须在运行时设置的静态变量方法存储变量。方法是对象可以执行的操作一个方法在每个 C# 文件中只能使用一次。方法确定给定属性的状态。ArgumentNullValueInvalidFormatFoundExceptionIndexOutOfPocketArgumentNullExceptionfinally 块的主要目的是什么?finally 块用于处理异常。finally 块用于定义 try-catch 语句的主要逻辑。finally 块是可选的,在 try-catch 语句中不是必需的。finally 块用于确保无论是否发生异常,某些代码都会被执行。官方文档:Dictionary<TKey, TValue> 类
[参考]:https://www.gkseries.com/c-sharp-programming/multiple-choice-questions-and-answers
[参考]:https://www.gkseries.com/c-sharp-programming/multiple-choice-questions-and-answers