方法的调用delegate int test1(int a);class Program{static int num = 10;static void Main(string[] args){test1 t = new test1(max);t(40);Console.WriteLine("max,{0}", num);Console.ReadLine();}public static int max(int a){num += a;return num;}}
类额实例化class weituo {public int num = 10;//非静态public int max(int a){num += a;return num;}}Main ()
{weituo wt = new weituo();test1 t1 = new test1(wt.max...
在C#的List集合操作中,有时候需要将List元素对象拷贝存放到对应的数组Array中,此时就可以使用到List集合的CopyTo方法来实现,CopyTo方法是List集合的扩展方法,共有3个重载方法签名,分别为void CopyTo(T[] array)、void CopyTo(T[] array, int arrayIndex)、void CopyTo(int index, T[] array, int arrayIndex, int count)等三种形式,此文重点介绍CopyTo的第一种方法签名形式void CopyTo(T[] array)。首先定义个用于测试的类Te...
一般在做爬虫或者CMS的时候经常需要提取 href链接或者是src地址。此时可以使用正则表达式轻松完成。Regex reg = new Regex(@"(?is)<a[^>]*?href=([‘""]?)(?<url>[^‘""\s>]+)\1[^>]*>(?<text>(?:(?!</?a\b).)*)</a>");
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc) { richTextBox2.Text += m.Groups["url"].Value + "\n";//得到href值 ...
前两天看见扩展属性,瞬间感觉微软需要学习的东西实在是太多了,博大精深,我还差得很远,以下的扩展方法就是一个很好的东西。现在我先建立一个modelpublicclass Student{publicstring Id { get; set; }publicstring Name { get; set; }}View Code在实际场景中,可能我们需要在这个model里需要写一些方法,一些查询等等,但是我们在设计时希望model里面只是声明属性,其它方法不放在model里面,那么怎么做到两者兼容呢,扩展方法可...
此文章不断补充1、判断该字符串是否存在于字符串数组中1string[] arr = {"aaa","bbb","aba","ccc" };
2string str = "vv";
3 Console.WriteLine(arr.Contains(str)); 2、将字符串中的标点符号替换成空格1string str = "fdasjklfsdalj;dfsafjksdjkgd,fsdajklfjksldaklj klkfdska;fwefew.45fsd4521fsa3";
2string strRegex = Regex.Replace(str, @"\p{P}", "");
3 Console.WriteLine(strRegex); 原文:http:...
原文:【原创】开源Math.NET基础数学类库使用(12)C#随机数扩展方法 本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p/4288836.html开源Math.NET基础数学类库使用总目录:http://www.cnblogs.com/asxinyu/p/4329737.html前言 真正意义上的随机数(或者随机事件)在某次产生过程中是按照实验过程中表现的分布概率随机产生的,其结果是不可预测的,是不可见的。而计算机中的随机函数是按照一定算法模拟...
//这是一个json字符串 string str="{\"id\":1,\"name\":\"张三\",\"time\":\"2018-05-02T09:02:32.1869172+08:00\",\"money\":23.4,\"str\":[\"a\",\"b\",\"c\"]}"; //转化为对象 User user =(User) Jayrock.Json.Conversion.JsonConvert.Import(typeof(User),str);//获得对象myClass的所有属性组成的集合 propertys 需要引用using System.Reflection; PropertyInfo[] p = user.GetType().GetProperties(); ...
方法1:将图片复制到指定文件夹,在数据库中存储图片路径,通过读取路径来显示图片。string str;privatevoid toolStripButton1_Click(object sender, EventArgs e){if (openFileDialog1.ShowDialog() == DialogResult.OK){str = openFileDialog1.FileName;pictureBox1.Image = Image.FromFile(str);}}//打开文件并在PictureBox中显示图片privatevoid toolStripButton2_Click(object sender, EventArgs e){string filename = DateTi...
c# 操作txt文件
# 操作txt文件
c#创建文本privateconststring FILE_NAME = "ErroLog.txt";publicstaticvoid WriteFile(string str)...{StreamWriter sr; if (File.Exists(FILE_NAME)) //如果文件存在,则创建File.AppendText对象 ...{sr = File.AppendText(FILE_NAME);}else//如果文件不存在,则创建File.CreateText对象 ...{sr = File.CreateText(FILE_NAME);}sr.WriteLine(str);sr.Close();}C...
如果在win8,win7情况下报错:未知错误(0x80005000)见http://blog.csdn.net/ts1030746080/article/details/8741399using System;
using System.Collections;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;namespace IISControlHelper
{///<summary>/// IIS 操作方法集合///http://blog.csdn.net/ts1030746080/artic...
题外话:别指望看第一遍书就能记住和掌握什么——请看第二遍、第三遍。本人女猿一枚,2年工作经验,喜欢钻研,喜欢创新,闲暇之余喜欢写写博客,深知自身能力薄弱,如表达错误、不当之处请园友们多多指出,互相交流。三种泛型委托:1.predicate:定义:public delegate bool Predicate<in T>(T obj);这种委托返回值必须为bool型,可传入一个T类型参数;2.Action:定义:public delegate void Action<T>(T obj1,T obj2,.......T ob...
C#实现函数的超时退出功能主要是用到了System.Threading.Tasks.TaskFactory的StartNew()函数 privatestaticvoid Main(string[] args){Console.WriteLine("Begin:" + DateTime.Now);bool ret = Process(string.Empty, 10000);Console.WriteLine("Result={0}", ret);Console.WriteLine("End:" + DateTime.Now);Console.WriteLine("Press any key to exit...");Console.ReadKey(true);}privatestaticbool Process(string param, int t...
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Collections.Specialized;using System.IO;using System.Runtime.InteropServices;using System.Windows.Forms;namespace test{ /// <summary> /// IniFiles的类 /// </summary> public class IniFiles { public string FileName; //INI文件名 //string path = System.IO.Path.Combine(Applica...
参考自:http://bbs.csdn.net/topics/370031678 设置接收线程属性:Thread.IsBackground = true;关闭主线程时接收线程也会自动关闭。原文:http://www.cnblogs.com/yinsua/p/4526134.html
1:封装 将对象进行封装,并不等于将整个对象完全包裹起来,而是根据实际需要,设置一定的访问权限,用户根据不同的权限调用对象提供的功能,在C#语言中,可以使用修饰符public、internal、protected、private分别修饰类的字段、属性和方法。 2:继承,主要是注意继承的格式 [csharp] view plaincopypublic class ParentClass //父类 { public ParentClass(); } public class ChildClass : ParentClass :子类 { ...