I’m trying to practice my english skills, if you are willing to help me with terminology and grammar, please contact me by email or wechat or qq, great rewards await.
As I have learned lots of knowledges in work, writting cleanner C# codes are still challengeable for me. The book “effective C#”(referd as “The book” in context) is expected to be the saver for me.
item1 Prefer Implicitly Typed Local Variables
According to the book, implicit type “var” is introduced to support anonymous types in C#. In most cases, for example var foo = new MyType(); almost every one could recognize foo’s type at glance, but some cases behave in opposite manner. if you write something like
1 2 3
var f = GetMagicNumber(); var total = 100 * f / 6; Console.WriteLine($"Declared Type: {total.GetType().Name}, Value: {total}");
the output could be ambiguous. So such situation should be avoid on whatever.
msdn gives some examples and we can do more in practice
// Example #1: var is optional because // the select clause specifies a string string[] words = { "apple", "strawberry", "grape", "peach", "banana" }; var wordQuery = from word in words where word[0] == 'g' select word;
// Because each element in the sequence is a string, // not an anonymous type, var is optional here also. foreach (string s in wordQuery) { Console.WriteLine(s); }
// Example #2: var is required when // the select clause specifies an anonymous type var custQuery = from cust in customers where cust.City == "Phoenix" selectnew { cust.Name, cust.Phone };
// var must be used because each item // in the sequence is an anonymous type foreach (var item in custQuery) { Console.WriteLine("Name={0}, Phone={1}", item.Name, item.Phone); }
For the 1st example, it could be more efficient to let the compiler select a IQueryable<string> interface, and for the 2nd example, the anonymous type could be assigned as variables without type cast.
Type relationship in linq query operations
The following illustration shows a LINQ to Objects query operation that performs no transformations on the data. The source contains a sequence of strings and the query output is also a sequence of strings.
Relation of data types in a LINQ query
The type argument of the data source determines the type of the range variable.
The type of the object that is selected determines the type of the query variable. Here name is a string. Therefore, the query variable is an IEnumerable.
The query variable is iterated over in the foreach statement. Because the query variable is a sequence of strings, the iteration variable is also a string.
Prefer readonly to const
C# has two types of const variable, one in compile-time, other one is runtime. They behave quite different.
$ git checkout master Previous HEAD position was 3cb76a43 MOD: move virtual call fromconstructor, andresigterjsobjectasync Switchedtobranch 'master' Yourbranchisuptodatewith 'origin/master'.
然后你的主仓库会变成这样:
1 2 3 4 5 6 7 8 9 10 11
$ git status On branch master Your branch isupto date with 'origin/master'.
Changes not staged for commit: (use "git add <file>..."toupdate what will be committed) (use "git checkout -- <file>..."to discard changes in working directory)
modified: subproject/tutor-wpf-common (new commits)
nochanges added to commit (use "git add"and/or"git commit -a")
主要是为了监视EXIT信号 long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data); PTRACE_TRACEME Indicate that this process is to be traced by its parent. A process probably shouldn’t make this request if its parent isn’t expecting to trace it. (pid, addr, and data are ignored.)
The PTRACE_TRACEME request is used only by the tracee; the
remaining requests are used only by the tracer. In the
following requests, pid specifies the thread ID of the tracee
to be acted on. For requests other than PTRACE_ATTACH,
PTRACE_SEIZE, PTRACE_INTERRUPT, and PTRACE_KILL, the tracee
must be stopped.
My name is Laizenan, I’m currently junior student of Shanghai University. When I first come in School of Computer, I was addicted to programming contest and plunged bunches of time writing c plus plus to solve standard problems. I get lots of experiences and prove myself in ACM International Collegiate Programming Contest contests. I and my teammate get three bronze medals in 2016 and we win a silver medal and two bronze medals in 2017. The best one I regard as is the silver prize in Xi’an Regional, at the last moment, we solved a problem combining linear basis and segment tree, which sent us to the 29th position in three hundred teams and more than one hundred universities. Within one and a half years, I learned how to cooperate with my teammates and earned lots of coding experiences. I’m currently writing a new Online Judge for ACM club, where I practices my cpp and python skills. Do you need any further infomation about me ?
1001 and 1011 is solved instantly, however, I failed to notice a critical feature in 1002, and stuck on it for hours, no need to say that other problem is too difficult for me.