zoukankan      html  css  js  c++  java
  • [Tip: property]C#3.0 autoimplemented property

    The pattern of properties encapsulating a single field is so common that C# 3.0 introduced auto-implemented properties. Here’s an example:

    public int Rating { get; set; }

    This Rating property encapsulates some value of type int. Because calling code doesn’t have access to the backing store anyway, knowing its name doesn’t matter. The C#
    compiler will create an int field behind the scenes for us. 

    The VS2008 Property Snippet
    There’s another nice snippet in VS2008 that you can use for properties. Here’s how to
    use it:
    1. Click inside of the WebSite class. Create a class named WebSite if you haven’t
    created it yet.
    2. Type pro, press Tab, and you’ll see prop fill out. There are other property snippets,
    but we only want to use prop right now.
    3. Press Tab again to get the property snippet form. The highlight will be on the property
    type, which defaults to int.
    4. Type Web, and then press Tab. You’ll see WebSite fill out.
    5. Press Tab and you’ll see control move to the next place in the form, which is the
    name of the property.
    6. Type BetaSite and then press Enter. You’ll see the cursor move to the end of the
    snippet.
    This created an automatic property. 

  • 相关阅读:
    java实现同步的两种方式
    JAVA线程概念
    XML基础总结
    JAVA使用和操作properties文件
    JAVA序列化基础知识
    easyui 在编辑状态下,动态修改其他列值。
    Activiti初学问题,求解
    java web--DOM
    java web(1)
    Java WEB
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1671738.html
Copyright © 2011-2022 走看看