-
C# 创建一个泛型接口
C# 创建一个泛型接口的例子,创建一个泛型接口的代码和方法如下:
public interface IGenericInterface {
T CreateInstance(); //接口中调用CreateInstance方法
}
//实现上面泛型接口的泛型类
//派生约束where T : TI(T要继承自TI)
//构造函数约束where T : new()(T可以实例化)
public class Factory : IGenericInterface where T : TI, new()
{
public TI CreateInstance()//创建一个公共方法CreateInstance
{
return new T();
}
}
class Program
{
static void Main(string[] args)
{
//实例化接口
IGenericInterface factory =
Factory();
//输出指定泛型的类型
Console.WriteLine(factory.CreateInstance().GetType().ToString());
Console.ReadLine();
}
}
- 2022-03-11 00:59:39下载
- 积分:1
-
Visual C# 交叉表查询
这是一个Visual C# 交动态交叉表查询示例程序,动态交叉表(SQLServer 2005)查询例子源码:
private void Frm_Main_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(//创建数据库连接对象
@"Server=WIN-GI7E47AND9RLS;database=db_TomeTwo;Uid=sa;Pwd=");
SqlDataAdapter dap = new SqlDataAdapter(//创建数据适配器对象
"select * from tb_VenditionInfo", con);
DataSet ds = new DataSet();//创建数据集
dap.Fill(ds, "table");//填充数据集
dgv_Message.DataSource =//设置数据源
ds.Tables[0].DefaultView;
}
private void btn_Select_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(//创建数据库连接对象
@"Server=WIN-GI7E47AND9RLS;database=db_TomeTwo;Uid=sa;Pwd=");
SqlDataAdapter dap = new SqlDataAdapter("Corss", con);//创建数据适配器
dap.SelectCommand.CommandType =//设置命令为存储过程
CommandType.StoredProcedure;
DataSet ds = new DataSet();//创建数据集
dap.Fill(ds, "table");//填充数据集
dgv_Message.DataSource =//设置数据源
ds.Tables[0].D
- 2022-12-26 00:25:03下载
- 积分:1
-
C# 演示Tile、FlipX、FlipY、FlipXY 四种模式如何实现
C# 演示Tile、FlipX、FlipY、FlipXY 四种模式如何实现,基于WPF的一个C#源代码,可借此源码了解下DrawingBrush()、FlipY、TileMode.FlipXY、TileMode.Tile等众多模式在C#中的代码是如何编写的,源代码在VS2015中可以编译,完整代码请单击下载链接。
- 2022-05-20 04:07:08下载
- 积分:1
-
C# 自定义组件的小例子及源代码
C# 自定义组件的小例子及源代码,包含自定义的UserControl组件和应用该组件的MainFrame主窗体程序,需要在工具箱里右键-》选项-》.Net组件注册一下就能用了。主要通过将xml绑定到TreeView控件完成菜单导航功能,可以在同一窗体中导航不同panel,也可以导航多窗口,需要添加新菜单,只需配置Menu.xml,Menu.xml中显示treeView树形菜单中的各节点数据,将除菜单外所有panel设置为不显示。
- 2022-11-10 22:05:03下载
- 积分:1
-
C# 实现简单的WPF版图片淡入淡出效果
C# 实现简单的WPF版图片淡入淡出效果。运行本效果实例,即可看到图片淡入淡出变化,先淡入再淡出,不停的变化。
- 2022-01-25 21:23:37下载
- 积分:1
-
7Zip
This file is part of SevenZipSharp. SevenZipSharp is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SevenZipSharp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with SevenZipSharp. If not, see .
- 2022-07-20 00:09:31下载
- 积分:1
-
C# 获取本地打印服务器后台文件的路径
Visual C# MyWinWPF.rar,核心代码分享如下:
private void button1_Click(object sender, RoutedEventArgs e)
{//获取本地打印服务器后台文件的路径
var MyPrintServer = new System.Printing.LocalPrintServer();
string MyInfo = "本地打印服务器后台文件的路径是:" + MyPrintServer.DefaultSpoolDirectory;
MessageBox.Show(MyInfo, "信息提示", MessageBoxButton.OK);
}
- 2022-01-23 11:13:33下载
- 积分:1
-
Visual C#对 XML操作的演示示例集
这是一个C#操作XML文件的示例集,可完成 如下功能演示:
枚举XML集合中的元素名称
枚举XML集合中的元素文本
判断XML元素在集合中是否存在
筛选XML中的子代元素集合
使用链接轴方法枚举XML元素
根据元素属性查找XML元素
根据元素名称查找XML元素
根据元素属性和名称查找XML元素
根据中间计算值查找XML元素
比如枚举XML集合中的元素文本:private void button2_Click(object sender, EventArgs e)
{//枚举XML集合中的元素文本
XElement MyXElements = new XElement("Root",
new XElement("贵州省", "贵阳市"),
new XElement("四川省", "成都市"));
IEnumerable MyXElement =
from MySelect in MyXElements.Elements()
select MySelect;
string MyInfo = "元素文本包括:";
foreach (XElement MyValue in MyXElement)
MyInfo += MyValue.Value + "、";
//显示:贵阳市、成都市
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK);
}
- 2022-03-14 22:11:51下载
- 积分:1
-
C# 获取Access数据库的数据表名称
C# 获取Access数据库的数据表名称,private void button1_Click(object sender, EventArgs e)
{//获取Access数据库的数据表名称
string MyAccessDBFile = @"F:Northwind.mdb";
string MyConnectString ="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +MyAccessDBFile;
var MyConnection = new System.Data.OleDb.OleDbConnection(MyConnectString);
MyConnection.Open();
var MyTables = MyConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
string MyInfo = MyAccessDBFile + "数据库的数据表包括:";
foreach (DataRow MyRow in MyTables.Rows)
{
string MyTable = MyRow["TABLE_NAME"].ToString();
MyInfo += MyTable + "、";
}
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK);
}
- 2023-01-05 19:40:03下载
- 积分:1
-
C# OpenRead获取网站源代码,并保存到TXT文件Stream流中
C#获取网页源代码,并将其保存为TXT文件,这里应用了OpenRead和Stream流方法,具体的实现,请参见以下代码:
richTextBox1.Text = string.Empty;
WebClient wclient = new WebClient();//实例化WebClient类对象
wclient.BaseAddress = textBox1.Text;//设置WebClient的基URI
wclient.Encoding = Encoding.UTF8;//指定下载字符串的编码方式
//为WebClient类对象添加标头
wclient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
//使用OpenRead方法获取指定网站的数据,并保存到Stream流中
Stream stream = wclient.OpenRead(textBox1.Text);
//使用流Stream声明一个流读取变量sreader
StreamReader sreader = new StreamReader(stream);
string str = string.Empty;//声明一个变量,用来保存一行从WebCliecnt下载的数据
//循环读取从指定网站获得的数据
while ((str = sreader.ReadLine()) != null)
{
richTextBox1.Text += str + "
";
}
//调用WebClient对象的DownloadFile方法将指定网站的内容保存到文件中
wclient.DownloadFile(textBox1.Text, DateTime.Now.ToFileTime() + ".txt");
MessageBox.Show("保存到文件成功");
- 2022-02-02 08:55:49下载
- 积分:1