国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

一個(gè)泛型的問(wèn)題。

2019-11-14 16:25:14
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

前段時(shí)間我還在納悶,在上上篇設(shè)計(jì)模式的單例模式中,我只New過(guò)一次對(duì)象。但是查看我分明得到了2個(gè)或多個(gè)不同的對(duì)象。今天做個(gè)試驗(yàn)。代碼如下

通過(guò)實(shí)驗(yàn)發(fā)現(xiàn),對(duì)象確實(shí)是new了兩次,initial確實(shí)是進(jìn)入了兩次,對(duì)于不同泛型對(duì)象,是要重新開(kāi)辟內(nèi)存的。

下面的文章做個(gè)資料保存。

http://m.survivalescaperooms.com/DebugLZQ/archive/2012/09/03/2669383.html

http://msdn.microsoft.com/en-US/library/f4a6ta2h(v=vs.80).aspx

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5  6 namespace Consoleapplication10 7 { 8     class PRogram 9     {10         static void Main(string[] args)11         {12             generictest<custom1>.List.Add(new custom1("custom1(1)"));13             generictest<custom1>.List.Add(new custom1("custom1(2)"));14             generictest<custom2>.List.Add(new custom2("custom2(1)"));15             generictest<custom2>.List.Add(new custom2("custom2(2)"));16             Console.ReadKey();17         }18     }19     class generictest<T>20     {21         private generictest()22         { }23         static private List<T> list=null;24          static public List<T> List25          {26              set27              {28 29                  list = value;30              }31              get32              {33                  if (list == null)34                  {35                      initial();36                  }37                  return list;38              }39          }40 41          private static void initial()42          {43              list = new List<T>();44          }45     }46     class custom147     {48         public  string str;49         public custom1(string str)50         { 51         this.str=str;52         }53     }54     class custom255     {56      public  string str;57         public custom2(string str)58         { 59         this.str=str;60         }61     62     }63 }

 


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 东方市| 南溪县| 瑞金市| 沙湾县| 栾城县| 游戏| 普洱| 东安县| 民丰县| 丰宁| 北辰区| 涞源县| 德化县| 东平县| 和林格尔县| 共和县| 清镇市| 孟津县| 赤城县| 错那县| 内丘县| 柘城县| 和田市| 阜城县| 永川市| 台北市| 扎兰屯市| 河东区| 抚顺县| 辽中县| 肥乡县| 中山市| 蕲春县| 万载县| 宁城县| 阿坝县| 柳林县| 墨江| 嵩明县| 库尔勒市| 哈尔滨市|