C#
Bryan要加油
这个作者很懒,什么都没留下…
展开
-
[Effective c#]45.考虑在方法约定遭到违背时抛出异常
如果方法不能够完成其所宣称的操作,那么就应该通过异常来指出这个错误。错误码 VS 异常错误码是方法签名的一部分,经常会用来传达一些与错误无关的信息,而异常是专门用来报告错误的。由于异常本身也是类,可以从其中派生自己的异常类型,从而表达出较为丰富的错误信息。错误码必须由调用该方法的人来处理,而异常则可以沿着调用栈向上传播,直到到达合适的catch语句。异常不会轻易为人所忽视。如果没有适当的catch子句能够处理异常,那么程序就会明确地终止,而不会悄无声息地继续运行下去。如果某方法与其调用者之间的原创 2021-06-17 08:52:44 · 93 阅读 · 0 评论 -
[C#]?? 和 ??= 运算符
https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/operators/null-coalescing-operator原创 2021-05-20 08:57:33 · 508 阅读 · 0 评论 -
[C#]Null 条件运算符 ?. 和 ?[]
https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/operators/member-access-operators#null-conditional-operators–and-原创 2021-05-20 08:56:53 · 640 阅读 · 0 评论 -
[C#]字符串内插$、逐字字符串标识符@与复合格式设置
https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/tokens/interpolatedhttps://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/tokens/verbatimhttps://docs.microsoft.com/zh-cn/dotnet/standard/base-types/composite-formatting原创 2021-05-20 08:54:43 · 895 阅读 · 0 评论 -
c# What happens in an async method
The most important thing to understand in asynchronous programming is how the control flow moves from method to method. The following diagram leads you through the process:The numbers in the diagram correspond to the following steps, initiated when a cal原创 2021-05-17 22:56:06 · 559 阅读 · 0 评论 -
C# Tasks
Compared to a thread, a Task is higher-level abstraction—it represents a concurrent operation that might or might not be backed by a thread. Tasks are compositional (you can chain them together through the use of continuations). They can use the thread poo原创 2021-04-08 09:09:29 · 778 阅读 · 0 评论 -
C# Threading
A thread is an execution path that can proceed independently of others.Each thread runs within an operating system process, which provides an isolated environment in which a program runs. With a single-threaded program, just one thread runs in the process原创 2021-04-07 16:31:57 · 518 阅读 · 0 评论 -
C# LINQ Operators
Standard query operators fall into three categories:Sequence in, sequence out (sequence→sequence)Sequence in, single element or scalar value outNothing in, sequence out (generation methods)Sequence→SequenceFILTERINGIEnumerable< TSource > →IEn原创 2021-04-07 15:57:17 · 704 阅读 · 0 评论 -
C# Boxing and Unboxing
Boxing is the act of converting a value-type instance to a reference-type instance. The reference type can be either the object class or an interface (which we visit later in the chapter).1 In this example, we box an int into an object:int x = 9;object o原创 2021-04-06 16:03:50 · 725 阅读 · 0 评论 -
C# Sealing Functions and Classes
An overridden function member can seal its implementation with the sealed keyword to prevent it from being overridden by further subclasses. In our earlier virtual function member example, we could have sealed House’s implementation of Liability, preventin原创 2021-04-06 15:51:56 · 684 阅读 · 0 评论 -
C# nameof
The nameof operator returns the name of any symbol (type, member, variable, and so on) as a string:int count = 123;string name = nameof (count); // name is "count"Its advantage over simply specifying a string is that of static type checking. Tool原创 2021-04-06 15:37:58 · 477 阅读 · 0 评论 -
C# Partial Types and Methods
Partial TypesPartial types allow a type definition to be split—typically across multiple files. A common scenario is for a partial class to be autogenerated from some other source (such as a Visual Studio template or designer), and for that class to be au原创 2021-04-06 15:35:34 · 607 阅读 · 0 评论 -
c# indexer
To write an indexer, define a property called this, specifying the arguments in square brackets:class Sentence{ string[] words = "The quick brown fox".Split(); public string this [int wordNum] // indexer { get { return words [wordNum]; }原创 2021-04-06 15:26:30 · 554 阅读 · 0 评论 -
C# Class Property
Properties look like fields from the outside, but internally they contain logic, like methods do. For example, you can’t tell by looking at the following code whether CurrentPrice is a field or a property:Stock msft = new Stock();msft.CurrentPrice = 30;原创 2021-04-06 15:24:05 · 271 阅读 · 0 评论 -
C# Object Initializers
To simplify object initialization, any accessible fields or properties of an object can be set via an object initializer directly after construction. For example, consider the following class:public class Bunny{ public string Name; public bool LikesC原创 2021-04-06 15:12:42 · 654 阅读 · 0 评论 -
C# null operators
Null-Coalescing OperatorThe ?? operator is the null-coalescing operator. It says, “If the operand to the left is non-null, give it to me; otherwise, give me another value.” For example:string s1 = null;string s2 = s1 ?? "nothing"; // s2 evaluates to "原创 2021-04-06 13:26:39 · 644 阅读 · 0 评论 -
c# value type & reference type
Value typeThe content of a value type variable or constant is simply a value. For example, the content of the built-in value type, int, is 32 bits of data.You can define a custom value type with the struct keyword.Point p1 = new Point();p1.X = 7;Poi原创 2021-04-06 11:36:28 · 290 阅读 · 0 评论 -
C# 双问号(??)运算符
如果左操作数的值不为 null,则 null 合并运算符 ?? 返回该值;否则,它会计算右操作数并返回其结果。 如果左操作数的计算结果为非 null,则 ?? 运算符不会计算其右操作数。private static void Display<T>(T a, T backup){ Console.WriteLine(a ?? backup);}...原创 2021-02-02 14:31:46 · 476 阅读 · 0 评论 -
c# async await
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/version 0using System;using System.Threading.Tasks;namespace Async_Await{ class Program { class Coffee { } class Egg { } class Bacon { }翻译 2021-02-01 15:51:43 · 197 阅读 · 0 评论