C # small knowledge point accumulation,

Source: Internet
Author: User

C # small knowledge point accumulation,

1,Sealed Modifier

Concept:

C # proposes a sealed class to help developers solve this problem. The sealed modifier is used in the Declaration to prevent the class from being inherited by other classes. If you try to use a sealed class as the base class of other classes, C # will prompt an error. Naturally, the sealed class cannot be an abstract class at the same time, because the abstract always wants to be inherited. Sealed (C # reference) the sealed modifier can be applied to classes, instance methods, and attributes. The sealed class cannot be inherited. The sealing method will override the methods in the base class, but it cannot be further rewritten in any derived class. The sealed modifier must always be used with override (C # reference) [http://msdn2.microsoft.com/zh-cn/library/ebca9ah3 (VS.80). aspx] when applied to methods or properties.

Purpose:

Currently, I only use this modifier in singleton mode:

First, make a simple description of the singleton mode (for my understanding, please note that there is an error): requirement 1st: ensure that one class has only one instance.

In this way, we should think that when we want to call non-static methods in this Class, we can no longer use the Class c = new Class (); we are familiar with to instantiate it first, and then click ~

For example, in the following example, we have written something in the Test method. If we want to call this method, since it cannot be instantiated normally, we will try another method. That is to say, this class must provide us with a global access point to access it.

This is the 2nd requirement of the singleton mode, as shown in the exampleGetInstance ();The code is very simple and can be understood by everyone.

Public sealed class IndexManager {# region Singleton mode the hunger mode ensures that only one instance is created during the entire application running cycle (the GetInstance method obtains the instance) private readonly static IndexManager instance = new IndexManager (); private IndexManager () {}/// <summary> /// global access point for the whole Singleton mode /// </summary> /// <returns> </returns> public static IndexManager GetInstance () {return instance;} # endregion public void Test (){...}}

2. When designing a table, the Id is set to GUID type, which is faster than the self-increasing type when data is inserted.

Because self-growth requires statistics on the original data volume, locking and updating. In the design of some non-Relational Tables, you can consider using GUID-type primary key IDs.

For example, keyword statistics in the search module.

3. Quarzt introduction, third-party scheduled task framework

Tip: over time, small knowledge can also be built into a good conversation. Joke, update it slowly, and use it on a daily basis. It is not a point that will easily attract everyone's attention. I will try to put it all in this article.

Related Article

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.