前两天看见扩展属性,瞬间感觉微软需要学习的东西实在是太多了,博大精深,我还差得很远,以下的扩展方法就是一个很好的东西。现在我先建立一个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 :子类 { ...
l>
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
<![endif]-->
endif]-->yle>
/* Style Definitions */
table.MsoNormalTable
{
mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
<![endif]-->开发语言:C#3.0
IDE:Visual Studio 2008
本系列教程主要包括如下内容:
1. BeginInvoke和EndInvoke方法
2. Thread类
3. 线程池
4. 线程同...
看下组织结构:System.Object System.MarshalByRefObject System.Threading.WaitHandle System.Threading.Mutex System.Threading.Semaphore System.Threading.EventWaitHandle System.Threading.ManualResetEvent System.Threading.AutoResetEvent System.Object System.Threading.Interlocked System.Thre...
经常看到有些VB的例子中直接用个CreateObject就可调用系统功能(大多是COM对象),像用户设定,网络设定等等。虽然C#中可以通过使用VB的命名空间的方法来调用CreateObject函数,但是这样比较没什么用,因为生成的对象的所带有的方法都不能使用。C#中还可以直接用添加引用的方式来调用一些对象,前提是你知道该添加哪个引用。当我上网搜索,已经搜索到很多VB的成功用CreateObject调用的例子,C#的例子却很难找到的时候,就干脆用类似...