• <sub id="h4knl"><ol id="h4knl"></ol></sub>
    <sup id="h4knl"></sup>
      <sub id="h4knl"></sub>

      <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
      1. <strong id="h4knl"></strong>

      2. 筆試題const 和 static readonly

        時(shí)間:2020-10-15 17:11:37 筆試題目 我要投稿

        筆試題(const 和 static readonly)

        const 和 static readonly 區(qū)別?

        筆試題(const 和 static readonly)

        答:const
        用 const 修飾符聲明的成員叫常量,是在編譯期初始化并嵌入到客戶端程序

        static readonly用 static readonly 修飾符聲明的成員依然是變量,只不過具有和常量類似的使用方法:通過類進(jìn)行訪問、初始化后不可以修改。但與常量不同的是這種變量是在運(yùn)行期初始化

        示例:

        測試類:using System;using System.Collections.Generic;using System.Text; namespace Example02Lib{    public class Class1    {        public const String strConst = "Const";        public static readonly String strStaticReadonly = "StaticReadonly";        //public const String strConst = "Const Changed";        //public static readonly String strStaticReadonly = "StaticReadonly
        Changed";    }} 客戶端代碼:using System;using System.Collections.Generic;using System.Text;using Example02Lib; namespace Example02{    class Program    {        static void Main(string[] args)        {            //修改Example02中Class1的strConst初始值后,只編譯Example02Lib項(xiàng)目            //然后到資源管理器里把新編譯的Example02Lib.dll拷貝Example02.exe所在的.目錄,
        執(zhí)行Example02.exe            //切不可在IDE里直接調(diào)試運(yùn)行因?yàn)檫@會(huì)重新編譯整個(gè)解決方案!!             //可以看到strConst的輸出沒有改變,而strStaticReadonly的輸出已經(jīng)改變            //表明Const變量是在編譯期初始化并嵌入到客戶端程序,而StaticReadonly是在運(yùn)行時(shí)初始化的            Console.WriteLine("strConst : {0}", Class1.strConst);            Console.WriteLine("strStaticReadonly : {0}", Class1.strStaticReadonly);             Console.ReadLine();        }    }}結(jié)果:
        strConst : Const
        strStaticReadonly : StaticReadonly

        修改后的示例:

        測試類:

        using System;using System.Collections.Generic;using System.Text; namespace Example02Lib{    public class Class1    {        //public const String strConst = "Const";        //public static readonly String strStaticReadonly = "StaticReadonly";        public const String strConst = "Const Changed";        public static readonly String strStaticReadonly = "StaticReadonly Changed";    }}結(jié)果

        strConst : Const
        strStaticReadonly : StaticReadonly Changed

        【筆試題(const 和 static readonly)】相關(guān)文章:

        理解PHP5中static和const關(guān)鍵字的差別11-14

        華為2017筆試題08-16

        360筆試題目10-20

        Javascript中設(shè)立對象的ReadOnly屬性11-22

        華為2017筆試試題08-10

        桂林銀行筆試題筆經(jīng)10-21

        不同美甲筆的保養(yǎng)和清洗方法10-07

        硬筆書法和軟筆書法的差別09-24

        QMS2007筆試審核知識模擬試題11-02

        php中static靜態(tài)變量的使用方法11-16

        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码
      3. <sub id="h4knl"><ol id="h4knl"></ol></sub>
        <sup id="h4knl"></sup>
          <sub id="h4knl"></sub>

          <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
          1. <strong id="h4knl"></strong>

          2. 五月丁香六月婷在线综合 | 一区二区日本精品理论片 | 亚洲国产91一区二区 | 亚洲AV秘片一区二区三 | 最新日韩欧美理论在线 | 中文字幕在线视频免费 |