易截截图软件、单文件、免安装、纯绿色、仅160KB

C# 单实例设计模式

Singleton模式的实现
Singleton模式的实现基于两个要点:
1)不直接用类的构造函数,而另外提供一个Public的静态方法来构造类的实例。通常这个方法取名为Instance。Public保证了它的全局可见性,静态方法保证了不会创建出多余的实例。
2)将类的构造函数设为Private,即将构造函数"隐藏"起来,任何企图使用构造函数创建实例的方法都将报错。这样就阻止了开发人员绕过上面的Instance方法直接创建类的实例。
通过以上两点就可以完全控制类的创建:无论有多少地方需要用到这个类,它们访问的都是类的唯一生成的那个实例。以下C#代码展现了两种实现Singleton模式的方式,开发人员可以根据喜好任选其一。
实现方式一:Singleton.cs
using System;
class SingletonDemo

 private static SingletonDemo theSingleton = null;
 private SingletonDemo() {}
 public static SingletonDemo Instance()
 {
  if (null == theSingleton)
  {
   theSingleton = new SingletonDemo();
  }
  return theSingleton;
 }
}
 void Main(string[] args)
 { SingletonDemo s1 = SingletonDemo.Instance();
  SingletonDemo s2 = SingletonDemo.Instance();
  if (s1.Equals(s2))
  { Console.WriteLine("see, only one instance!");
  }
 }


相关文档:

C# 加密-RSA 高级

RSA
实际应用中是:接收方产生公钥和私钥,发送方用其公钥加密,再把加密后的内容发送给接收方。
CspParameters
的名称空间是:
System.Security.Cryptography
CspParameters cpSend = new CspParameters(); //Csp = Cryptography Service Provider
CspParameters cpReceive = new CspParameters();
cpSend.KeyCon ......

C#开发XML WebService接口(SOAP)

原文链接:http://www.cnblogs.com/ding0910/archive/2007/07/12/815407.html
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using BX.Interface; ......

c#中调用JavaScript脚本函数的一种方法

利用            Page.RegisterStartupScript("", "<script language='javascript'> results();</script>");    
      或者是         Page.RegisterClient ......

asp.net c# request常用

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace pub.mo
{
public class request
{
private request() { }
/// <summary>
/// 获取session
/// </summary>
/// <param name="_session_name" ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号