zoukankan
html css js c++ java
C# 范型编程
Using directives
#region
Using directives
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Reflection;
#endregion
namespace
GenericsSingleton
...
{
/**/
///
<summary>
///
单例范型
///
</summary>
///
<typeparam name="T"></typeparam>
public
class
Singleton
<
T
>
...
{
private
static
T _instance;
public
Singleton()
...
{
}
public
static
T Instance
...
{
get
...
{
if
(_instance
==
null
)
...
{
//
获得实例,使用这个方法的前提是T要有公有的、无参数的构造函数
_instance
=
(T)System.Activator.CreateInstance(
typeof
(T));
}
return
_instance;
}
}
}
/**/
///
<summary>
///
要实现单例的类
///
</summary>
public
class
Foo
...
{
private
int
count
=
0
;
public
int
Count
...
{
get
...
{
count
++
;
return
count;
}
}
}
/**/
///
<summary>
///
主函数
///
</summary>
class
Program
...
{
static
void
Main(
string
[] args)
...
{
//
连续调用三次如果值是递增的话说明三次调用都是同一个实例
Console.WriteLine(Singleton
<
Foo
>
.Instance.Count);
Console.WriteLine(Singleton
<
Foo
>
.Instance.Count);
Console.WriteLine(Singleton
<
Foo
>
.Instance.Count);
Console.ReadLine();
}
}
}
查看全文
相关阅读:
【HDU1724】Ellipse-自适应Simpson积分法
【HDU1724】Ellipse-自适应Simpson积分法
【51Nod1227】平均最小公倍数-杜教筛
【51Nod1227】平均最小公倍数-杜教筛
【HDU5628】Clarke and math-狄利克雷卷积+快速幂
【HDU5628】Clarke and math-狄利克雷卷积+快速幂
deleted
deleted
deleted
deleted
原文地址:https://www.cnblogs.com/xiaotuni/p/2365744.html
最新文章
(转)【D3D11游戏编程】学习笔记五:D3D11初始化
(转)【D3D11游戏编程】学习笔记三:XNAMath之XMMATRIX
(转)【D3D11游戏编程】学习笔记二:XNAMath之XMVECTOR
(转)【D3D11游戏编程】学习笔记一:最新版D3D11龙书
(转载)虚幻引擎3--官网--虚幻脚本中的字符串处理
(转载)虚幻引擎3--UE3垃圾回收机制
mac安装最新版本的git
怎样从命令行进入mac桌面
压缩 javascript 和 css
nginx reload
热门文章
在服务器上远程链接另一台服务器的数据库的方法how to connet the database from the other host
FATAL: ActionView::Template::Error (application.css isn't precompiled):
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
重构edit 和 new页面
Can't connect to local MySQL Server throught socket '/var/run/mysqld/mysqld.sock'(2)
ruby开发过程中的小总结
【POJ3207】Ikki's Story IV
【POJ3207】Ikki's Story IV
【HDU4498】Function Curve-分段+自适应Simpson积分法
【HDU4498】Function Curve-分段+自适应Simpson积分法
Copyright © 2011-2022 走看看