【c# 编程中常用的一些方法】教程文章相关的互联网学习教程文章

C#时间戳的获取与转换方法【代码】

///<summary>/// 获取当前时间戳///</summary>///<param name="bflag"></param>///<returns></returns>publicstaticstring GetTimeStamp(){return GetTimeStamp(DateTime.Now);}///<summary>/// 获取指定时间戳///</summary>///<param name="date"></param>///<returns></returns>publicstaticstring GetTimeStamp(DateTime date){TimeSpan ts = date - new DateTime(1970, 1, 1, 0, 0, 0, 0);return Convert.ToInt64(ts.TotalSeco...

C# ,.net 对比两个List的方法 亲测

方案一:for循环方法等 效率过慢 数据量过大时容易卡死 不建议使用 方案二:取交集 var intersection = datalist.Intersect(ExelLsit.,new TarGetComparer()).ToList();//需要重写IEqualityComparer Equals /// </summary> //public class TarGetComparer : IEqualityComparer<arko_dim_update_id_trial> //{ // public bool Equals(arko_dim_update_id_trial x, arko_dim_update_id_trial y) ...

VB.NET,C#.NET调用Web Service,利用visual studio 的实现方法【代码】

在VB.NET调用Web Service提供的服务技术qq交流群:JavaDream:251572072 下面是一篇文章比较详细,其实具体操作很简单,把Web Service服务地址,利用工具(VS2010),通过添加引用的形式,添加到项目中来就可以应用了. 大家如果这个地方不会操场的话,可以问问我QQ:1606841559   当Web Service已经处于对外提供服务状态,VB.NET就可以通过HTTP"调用"来使用这些服务了。当然前提是要了解Web Service对外提供服务所对应的URL,当了解到Web ...

c#中的委托使用(方法的调用, 和类的实话)【代码】

方法的调用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#中使用CopyTo方法将List集合元素拷贝到数组Array中【代码】

在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...

C#中使用正则表达式提取超链接地址的集中方法【代码】

一般在做爬虫或者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值 ...

c# 扩展方法【代码】【图】

前两天看见扩展属性,瞬间感觉微软需要学习的东西实在是太多了,博大精深,我还差得很远,以下的扩展方法就是一个很好的东西。现在我先建立一个modelpublicclass Student{publicstring Id { get; set; }publicstring Name { get; set; }}View Code在实际场景中,可能我们需要在这个model里需要写一些方法,一些查询等等,但是我们在设计时希望model里面只是声明属性,其它方法不放在model里面,那么怎么做到两者兼容呢,扩展方法可...

c#部分常用方法【代码】

此文章不断补充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#随机数扩展方法【代码】

原文:【原创】开源Math.NET基础数学类库使用(12)C#随机数扩展方法 本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p/4288836.html开源Math.NET基础数学类库使用总目录:http://www.cnblogs.com/asxinyu/p/4329737.html前言  真正意义上的随机数(或者随机事件)在某次产生过程中是按照实验过程中表现的分布概率随机产生的,其结果是不可预测的,是不可见的。而计算机中的随机函数是按照一定算法模拟...

C#遍历对象的方法【图】

//这是一个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(); ...

C#:将图片文件上传到数据库两种方法。【代码】

方法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文件的方法大全【代码】

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...

C# 操作IIS方法集合【代码】【图】

如果在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...

c#匿名方法【代码】

题外话:别指望看第一遍书就能记住和掌握什么——请看第二遍、第三遍。本人女猿一枚,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# 调用方法超时直接返回的功能【代码】

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...