improve watchespn quality

Want to know improve watchespn quality? we have a huge selection of improve watchespn quality information on alibabacloud.com

157 recommendations for writing high-quality code to improve C # programs--recommendation 14: correctly implement shallow and deep copies

. MemberwiseClone (); } #endregion PublicEmployee Deepclone () {using(Stream Objectstream =NewMemoryStream ()) {IFormatter Formatter=NewBinaryFormatter (); Formatter. Serialize (Objectstream, This); Objectstream.seek (0, Seekorigin.begin); returnFormatter. Deserialize (Objectstream) asEmployee; } } PublicEmployee Shallowclone () {returnClone () asEmployee; } }Turn from: 157 recommendations for writing high-

157 recommendations for writing high-quality code to improve C # programs--recommendation 46: Explicitly releasing resources requires an inherited interface IDisposable

unmanaged Resources if(Nativeresource! =IntPtr.Zero) {Marshal.freehglobal (Nativeresource); Nativeresource=IntPtr.Zero; } //let the type know that they have been releaseddisposed =true; } Public voidSamplepublicmethod () {if(disposed) {Throw NewObjectDisposedException ("SampleClass","SampleClass is disposed"); } //omitted } } classanotherresource:idisposable { Public voidDispose () {}}Inheriting the IDisposable interface also facilitates the

157 recommendations for writing high-quality code to improve C # programs--Recommendation 7: Use 0 values as default values for enumerations

enumeration type week, you can explicitly remove the value of an element, and the compiler automatically counts from the 0 value, then the value of the element +1.Note that in addition to the 8th value of week above, if the element type of the enumeration type is integer, you can also assign the values of the other integral types to week: Week = (week)9; This code does not go wrong, output: 9.Turn from: 157 recommendations for writing high-quality

157 recommendations for writing high-quality code to improve C # programs--recommendation 45: Specifying contravariance for generic type parameters

Recommendation 45: Specifying contravariance for generic type parametersContravariance refers to a method's parameters can be a base class for a delegate or a generic interface's parameter type. Common delegates that support contravariance in FCL4.0 are:FuncPredicateCommon delegates are:IcomparerThe following example shows the benefits of specifying the inverse of a generic type parameter: classProgram {Static voidMain () {Programmer P=NewProgrammer {Name ="Mike" }; Manager m=NewManager {Name

157 recommendations for writing high-quality code to improve C # programs--Recommendation 42: Using generic parameters to be compatible with the immutability of generic interfaces

stringName {Get;Set; } } classProgrammer:employee {}classManager:employee {}In Printsalary this method, the type that the method receives is isalaryCannot convert from "mytest.isalaryThe compiler checks the interface and delegate type parameters very strictly, unless the keyword out is specifically declared, otherwise this code will only compile failed. To get printsalary to complete the requirements, we can use generic type parameters: Static void Printsalary s) { s

157 recommendations for writing high-quality code to improve C # programs--Recommendation 3: Differentiating between forced transitions and as and is

Secondtype=NewSecondtype () {Name ="Second Type" }; Firsttype FirstType1=(Firsttype) Secondtype; Firsttype firstType2= Secondtype asFirsttype; } } classFirsttype { Public stringName {Get;Set; } } classSecondtype:firsttype {}However, even if you can use a forced transformation, from an efficiency standpoint, we recommend that you use the as operator.Knowing the difference between forced transformation and as, let's look at the is operator. Another version of Dowithsomety

157 recommendations for writing high-quality code to improve C # programs--Recommendation 41: Implementing a standard event model

=NewFileuploadedeventargs () {fileprogress = - }; while(E.fileprogress >0) {          //Transfer code, omit e.fileprogress--; if(fileuploaded! =NULL) {fileuploaded ( This, E); } } } }Calling code: Static void Main (string[] args) { Fileuploader f1=new fileuploader (); + = f1_fileuploaded;F1. Upload (); } Static void f1_fileuploaded (object sender, Fileuploadedeventargs e) { Console.WriteLine

157 recommendations for writing high-quality code to improve C # programs--recommendation 16: Arrays should not be used in cases where the number of elements is variable

:"+Watch. Elapsed); } Private Static voidresizelist () {Listint> Iarr =Newlistint> (New int[] {0,1,2,3,4,5,6 }); Stopwatch Watch=NewStopwatch (); Watch. Start (); Iarr.add (0); Iarr.add (0); Iarr.add (0); Watch. Stop (); Console.WriteLine ("resizelist:"+Watch. Elapsed); }The output is:resizearray:00:00:00.0004441resizelist:00:00:0:0000036Of course, strictly speaking,,listTurn from: 157 recommendations for writing high-

157 recommendations for writing high-quality code to improve C # programs--recommendation 66: Correctly capturing exceptions in multiple threads

thread exception"); } Catch(Exception ex) { This. Dispatcher.invoke (Action)Delegate { Throwex; }); } }); T.start ();However, in addition to the two methods above, we recommend using event callbacks to wrap the worker thread's exception to the main thread. The benefit of handling exceptions in the form of event callbacks is to provide a uniform entry for exception handling. This approach will be elabor

157 recommendations for writing high-quality code to improve C # programs--Recommendation 76: Beware of thread priorities

threadCTS. Cancel (); Console.WriteLine ("T1num:"+t1num.tostring ()); Console.WriteLine ("T2num:"+t2num.tostring ()); } As a result we will find that if this program runs on a single-core computer, the priority is highest thread T1, and its output value will almost always be greater than the priority normal (default) thread T2.In C #, with thread and threadpool new threads, the default priority is normal. Although it is possible to modify the priority of a thread as in the example above, i

157 recommendations for writing high-quality code to improve C # programs-Recommendation 78: Avoid too many threads

(() = { while(true) {Console.WriteLine ("T201 is executing"); } }); t201. Start (); Console.readkey (); } In addition to the startup problem, there is the same problem with switching between threads, and the next execution of the T201 will wait for a considerable amount of time.Therefore, do not abuse threads, especially excessive threads. When you start a new thread, you need to think carefully whether the job really needs a new thread to complete. Even

157 recommendations for writing high-quality code to improve C # programs--Recommendation 87: Differentiate between WPF and WinForm threading models

the two methods as extension methods so that all UI types in the project can be used.WPF supports both methods, with all the code shown below (note the While loop section):Private voidButtonStart_Click (Objectsender, RoutedEventArgs e) {Task T=NewTask (() = { while(true) { This. Dispatcher.begininvoke (NewAction (() ={Textblock1.text=DateTime.Now.ToString (); })); Thread.Sleep ( +); } }); //to catch an exception, a new task is startedT.

157 recommendations for writing high-quality code to improve C # programs--recommendation 29: Distinguish between Ienumerable<t> and iqueryable<t> in LINQ queries

Recommendation 29: Distinguish between IenumerableLINQ queries provide a total of two types of extension methods, under the System.Linq namespace, there are two static classes: The Enumerable class, which extends for collections that inherit the IenumerableLINQ queries can actually be functionally divided into 3 classes: LINQ to OBJECTS, LINQ to SQL, LINQ to XML. The purpose of designing two sets of interfaces is to differentiate between LINQ to OBJECTS and LINQ to SQL, both of which are used in

Books to improve code quality

C # Programming style (English-Chinese comparison)The Elements of C # Style*net Design specification:. NET conventions, idiomatic methods and patternsFramework Design Guildline*. NET Design specification (CD-ROM attached)Framework Design Guildline (with CD)SQL Programming StyleJoe Celko ' s SQL programming Style [by Joe Celko. Turing]More effective C # Chinese version-50 specific ways to improve C # programsSharper C # code-writing high-

What if there are too many bugs in the team code? How to steadily improve the quality of your team's code

checklist can be checked against the list at the time of the code, avoiding repetitive errors, and the quality of the team's code will improve steadily as checklist accumulates.5, the development of code specifications and strict implementation, the violation of the problem recorded in checklist;In short, can be summed up as analysis + accumulation + sharing, no checklist accumulation, just rely on the exp

How to improve your code quality---using PMD

To improve the quality of your code, in addition to improving logical control and understanding of business processes, there is room for improvement in the code itself, such as some potential problems that can be avoided early. Similar to the content of the coding code, if all rely on the coder to do their own checks, it will undoubtedly require a lot of work, if you can use the static inspection tools to c

Improve and optimize the image quality of CS (half-life: Counter-strike) Counter-Terrorism elites and condition zero

Improve and optimize cs' anti-terrorism image effects/QualityNonsense: Anti-Terrorism 2!But counter-terrorism 2 has changed a lot, without the pleasure of CS. Our CS fans only use cs1.6.Cs1.6 releases zero-point action condition zeroHis Screen Effect is much better than that of cs1.6, and CS is very pleasant.Recently I found out how to improve the zero-point action picture-d3d mode. Why does CS2 not use the

Improve code quality Techniques

:Class A { function First () {$this->a = Get_large_array (); $this->pass_to_function (); } function Pass_to_function () {//process $this->a }}In short, to unset them as soon as possible, let the memory release, reduce the burden of the script.4. Error logfunction Insert_member () { if (! $model->insert ($data)) {Log::record ($model->geterror, Log::sql, ' Insert_ Member '); return false; }}Above is an Insert member information method, when inserting data failure, will record th

Improve the quality of advertising and effect process three: how to strengthen memory

The article introduced how to use the unconscious attention and intentional attention in the cognitive system of shallow processing to improve the quality and effectiveness of advertising. Next, we enter the third stage, phase three, including memory and association, the main role of the deep processing of information is persuasion, that is, through the analysis of Memory and association, the use of skills

Two ways to improve network connection quality

Many computer users will reflect that their network connection speed is too slow, especially slow download, some users of the network is worse, even the Web page can not open, but the monthly network costs still need to hand over to the landlord. So, is there any way to improve the network connection? Below, the small series to everyone to share two ways to improve the

Total Pages: 9 1 .... 5 6 7 8 9 Go to: Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.