effective c#

Want to know effective c#? we have a huge selection of effective c# information on alibabacloud.com

"Effective C + +" study notes-clause 02

concept of scope (scope) and access rules , so it can be encapsulated within a class , of course, this is a macro cannot do.Conclusion:Despite the const, enum, and inline, we have reduced the need for preprocessor, especially #define, but not completely eliminated. #include is still a necessity, #ifdef/#ifndef也继续扮演控制编译的重要角色. There is no time to retire to the preprocessor, but we can definitely give it a longer vacation.Please remember:① for simple constants, it is best to replace them with cons

"Effective C + +" study notes-clause 19

utilization, and the guarantees provided in these areas will add the appropriate constraints to your class implementation code. ? How generalized is your new type? If you are not creating a new type, but a "type family", you should not define a new class, but define a new one. ? Do you really need a new type? If you simply define a new derived class to add functionality to an existing class, you might be able to define a non-member or templates to achieve the goal. ☆ Please remembe

"Effective C + +" study notes (i)

original articles, reproduced please specify the source: http://blog.csdn.net/sfh366958228/article/details/38701767Objective"C + + Primer" and "effectivec++" has been recognized by C + + programmers Red Book books, this time brought is "effective C + +" study notes and experience."

More effective C + +----(12) Understand the difference between "throw an exception" and "pass a parameter" or "call a virtual function"

to a constWe immediately noticed another difference between passing parameters and passing exceptions. An object thrown by an exception (as explained earlier, always a temporary object) can be captured by a generic reference, and it does not need to be captured by a reference to a const object (reference-to-const). forwarding a temporary object to a parameter of a non-const reference type (see clause M19) is not allowed in a function call, but is allowed in the exception. Let's go back to the

"Effective C + +" Highlights (v)

The fifth chapter of effective C + +: realizing Delay the occurrence of variable definitions whenever possible. The readability of a program is often improved only if the variable is defined just before it is used, because it is not easy to forget the meaning of the variable that it represents. On the other hand, this can improve the performance of the program, if you do not need a variable to allocate,

Effective c++51

parameter passed to operator new[] may have a value that is larger than the memory of the generation object, since clause 16 mentioned that dynamically allocated arrays may contain additional space to hold the number of elements.Second , C + + guarantees that the deletion of pointers is always safe, so in the program, we operate with the following code for NULL pointers:voidoperatordelete(voidthrow(){ if(rawMemory==0return; 归还rawMemory所指内存;}fin

Effective C + + construction destructor assignment operation

virtual//Article 12: Do not forget every ingredient when copying an object//1. Copy all member variables of this class and call the appropriate copy function of its base class//2. The copy constructor is usually close to the work done by the copy assignment operator, but it is best not to let one call another, and a new function should be defined for the two functions to be called. //3. It is unreasonable to make the copy assignment operator call the copy constructor, because it is like trying

More effective C + + clause 70 million do not overload &&,| | And, operator

1. Built-in and | | The operator has a "short-circuit evaluation" feature. For if the first operand is true, then returns to true, no longer evaluates the second operand, | | Instead, use this feature to write the following code:Char *p; .. if (p>0strlen (P) >) ...View CodeOnce overloaded, and | | The left and right operand is two no points before and after the parameters, that is, the characteristics of short-circuit evaluation is not when the function is called, all parameters are evaluated

Effective C + + clause 18

Make the interface easy to use correctly, not easily misusedsuch as the topic, our own program interface is user-oriented, the purpose of the program is not only to solve the problem, but also to make users easy to use, so, we must ensure that our program interface has a strong robustness.How to ensure the robustness of the interface, different circumstances have different processing results, the author lists the following examples of the corresponding methods.1. Design a class to represent the

Effective c++--Clause 14 (chapter 3rd)

Auto_ PTR pursues the meaning of replication.Copying functions, including the copy constructor and the copy assignment operator, can be created automatically by the compiler, so you have to write them yourself unless the compiler builds what you want to do. Note:Copying a Raii object must replicate the resources it manages, so the copying behavior of the resource determines the copying behavior of the Raii object.The general and common RAII class copying behavior is: Suppress copying, execute t

"Effective C + +"-clause 17: Placing newed objects into smart pointers with separate statements

Suppose you have the following two functions:int Priority (); void processwidget (STD::TR1::SHARED_PTRThe call to Processwidget is as follows:Processwidget (STD::TR1::SHARED_PTRnew Widget, priority ());Before the compiler outputs a processwidget call code, you must first account for the individual arguments that will be passed. The first argument above consists of two parts: Execute the "new Widget" expression Call the Tr1::shared_ptr constructor So before calling Processwidget

Effective C + + 02 construction/destructor/assignment operation (to be continued)

delete the derived class object as you would like.When a class is not intended to be used as a base class, making its destructor virtual is often a bad idea.Because the virtual function is implemented, additional overhead is required (pointer vptr to the virtual function table).STL containers do not have virtual destructors, so it is best not to derive them.Please remember: A base class with polymorphic properties should declare a virtual destructor. If a class has any virtual func

Effective C + + clause 19: Design class like design type

. Who should take the new type member?Similar to the one above, is the encapsulation of classes, in some cases, member variables should be private, and in the public function provides access to these member variables get and set functions. If necessary, you can make the yuan, but friends should also use caution, because some compilers support is not very good, on the other hand, friends become a special case of the destruction of encapsulation, will bring security risks.10. What is an undeclared

Effective C + + 10,11 Operator= 's engagement and attention

1. Return a reference to *thisIt is customary to return a reference to itself, which can be done such as (a=c). Modify () a similar operation that can form a chained operation, otherwise the modification is just a temporary object. This is one of the most common builder patterns in Java2. Self-assignment detection and exception safetyBefore the assignment is self-detected, the same is returned directly. If it is not detected, it can easily cause the r

"Effective C + +" study notes-clause 03

member function: : Length () const{ if (!lengthisvalid) { textLength = Std::strlen (ptext);//Now it can be lengthisvalid = true; } return textLength;}So avoid duplication in the const and NON-CONST member functionsThis problem is caused by the above problem, although mutable can solve the problem of variables, but if this thing is very long,We're going to need some two long, long monsters, so scary!.This requires Non-const to invoke the const thing to avoid duplication,

"Effective C + +" Reading notes 3

according to the object.Unlike N and composite, private inheritance can cause empty base class optimizations, which can be important for library developers working on minimizing the size of objects.Article 40: Use multiple inheritance wisely and prudentlyThose classes that use virtual inheritance often produce objects that are larger than those that use non-virtual inheritance, and that accessing member variables of a virtual base class is slower than accessing a member variable of a non-virtua

[Effective modern C + + (11&14)] Chapter 2:auto

are proxy classes that are visible to the user, such as std::shared_ptr,std::unique_ptr. Other proxy classes are not visible to the user, such as: Std::vector The technology called expression templates used in some C + + libraries is also part of this category, which is designed to improve the efficiency of numerical calculation code. Example 2:= m1 + m2 + m3 + M4;If the operator+ operation returns a proxy class such as: SumBecause the type o

Effective C # Principle 31: Select small and simple functions

As an experienced programmer, no matter what language you used to use C # before, we synthesized a few practical ways to get you to develop effective code. Sometimes, the efforts we make in our previous environment are. NET environment is the opposite. Especially when you try to optimize some code manually. Your behavior often prevents the JIT compiler from making the most efficient optimizations. Your extr

"Effective C + +": Clause 41-clause 42

name to represent a traits member name.IterT> void workWithIterator(IterT iter) { typename::std::iterator_traits::value_type value_type; value_type temp(*iter); …… }Finally, TypeName related rules have different practices on different compilers. This means that the interaction between TypeName and nested subordinate names may cause headaches in terms of portability.Summarize When declaring the template parameter, the Prefix keyword class and typename are i

Item 8: Destructors do not throw exceptions effective C + + notes

in the destructor. The possible exceptions should be disposed of. Guarantees that the object can be completely freed . Since unsafe code always appears in destructors, we can only swallow exceptions or exit programs . Suchclass Dbconn{ Public: ~Dbconn{ if(!closed){ Try{ DB.Close(); } Catch(...) { Cerr"Database shutdown failed"Endl; //or exit the program directly //Std::abort (); }

Total Pages: 15 1 .... 9 10 11 12 13 .... 15 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.