
.net
文章平均质量分 81
cyb331
这个作者很懒,什么都没留下…
展开
-
C#翻译mobile-detect.js源码实现手机平台检测
mobile-detect移动端平台手机等信息检测开源地址:https://github.com/hgoebl/mobile-detect.jsC#翻译功能:获取手机操作系统,判断手机系统平台 public class DetectMobileBrowsers { private MobileDetectRules mobileDetectRules = new原创 2015-06-16 09:16:28 · 16758 阅读 · 0 评论 -
扩展将对象转换成字典
/// 对象转换为字典 /// /// /// /// public static Dictionary ToDictionary(this T obj) where T : class { var dictionary = new Dictionary()原创 2013-12-31 09:34:01 · 888 阅读 · 0 评论 -
C#多线程访问主线程UI元素
Thread t1 = new Thread(delegate()//匿名方法 { this.Invoke(new Action(delegate() //这里的this就是主线程UI的form { //...调用主原创 2013-11-15 16:30:16 · 1012 阅读 · 0 评论 -
C#读取资源文件Resource.resx
System.Resources.ResourceManager rs = new System.Resources.ResourceManager("NetWebBrowser.Resource", typeof(Resource).Assembly);//此处的 NetWebBrowser.Resource 表示:命名空间.资源类名var title = rs.GetString("t原创 2013-11-14 16:55:49 · 18765 阅读 · 3 评论 -
linq ToDictionary使用
例: public class Menu{public string Id{ get; set; } public string Name { get; set; }}static Dictionary test(IList menus) { var dic = new Dictionary();原创 2013-11-25 10:14:06 · 23135 阅读 · 0 评论 -
C#模拟web服务器
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.IO;namespace CodeTest{ class Program { static void转载 2013-11-20 10:19:33 · 852 阅读 · 0 评论 -
oracle ODP.NET 批量插入或更新
/// /// 批量插入数据/// /// 表名称/// 键-值存储的批量数据:键是列名称,值是该列对应的数据集合/// public int BatchInsert(string tableName, Dictionary columnRowData){ if (string.IsNullOrEmpty(tableName)) { throw n转载 2013-10-12 11:37:29 · 3710 阅读 · 0 评论 -
C#操作txt文件
//向txt写内容 public void WriteTxt(string content) { FileStream myStream = new FileStream(Server.MapPath("~/ProjectTest/commandLog.txt"), FileMode.Append, FileAccess.Write);原创 2012-11-19 15:04:30 · 1903 阅读 · 0 评论 -
读取配置文件
System.Configuration.ConfigurationManager.AppSettings["sd"];System.Configuration.ConfigurationManager.ConnectionStrings["sd"]原创 2013-09-24 11:39:37 · 529 阅读 · 0 评论 -
c# 将数组或集合 转换成以逗号分隔的字符串
样例:字符串数组为array,str为字符串数组转换成的字符串 string[] array = { etr, kdgj, 3454, tyt, gff }; string str=string.Join(",",array);经常忘记这个函数。记一下原创 2013-08-29 14:09:34 · 41141 阅读 · 3 评论 -
.NET反射记录
private void test() { T Ttype = (T)Activator.CreateInstance(typeof(T)); PropertyInfo[] Tpropertys = Ttype.GetType().GetProperties(); foreach (PropertyIn原创 2013-07-05 13:44:40 · 609 阅读 · 0 评论 -
实现自己的Dynamic类型
必须继承DynamicObject例:class ParamClass : DynamicObject { private Dictionary values = new Dictionary(); public override bool TryGetMember(GetMemberBinder binder, out object resu原创 2014-01-08 10:06:21 · 563 阅读 · 0 评论 -
MVC中通用JS判断表单或者某个具体的文本框验证是否通过
例: $("#idTest").click(function () { var t = $("#f1").valid(); var ele1=$("#f1").validate().element("#UserName") alert(t); alert(ele1);原创 2015-02-02 17:20:23 · 2397 阅读 · 0 评论 -
httpmodule通过httpfilter获取返回的网页内容
自定义httpmodulejfdmpublic virtual void Init(HttpApplication app) { // WARNING! This does not work with Windows authentication! // If you are using Windows authentication翻译 2014-07-17 19:15:09 · 1464 阅读 · 0 评论 -
C#中==与Equals区别
C#中的相等有两种类型:引用相等(ReferenceEquals)和值相等(Equals)。值相等就是说两个对象包含相同的值。而引用相等则比较的是两个对象的引用是否是同一个对象。也就是说,如果ReferenceEquals为True,则Equals必然为True,反过来就不一定了。这样的话可以看出来,ReferenceEquals我们没有比较去管他什么,系统自动解决,object类实现的静态R转载 2014-03-31 16:17:14 · 6558 阅读 · 0 评论 -
C#简单使用线程池
static void Main(string[] args) { ThreadPool.QueueUserWorkItem(ThreadWork, "t1"); ThreadPool.QueueUserWorkItem(ThreadWork, "t2"); ThreadPool.QueueUserWo原创 2014-04-01 14:10:44 · 657 阅读 · 0 评论 -
将定义查询模型转换成Lambda表达式
在进行lambda进行查询时,可能我们的查询原始条件不是lambda表达式树的形式,这时我们如何将其处理组装成lambda表达式树呢,下面的例子就是将一个对象的字体,运算符,值进行组装的例子public enum SearchMethod { /// /// 等于 /// Equal = 0, ///原创 2014-04-03 15:31:05 · 842 阅读 · 0 评论 -
c#枚举转化示例大全,数字或字符串转枚举
c#枚举转化示例大全,数字或字符串转枚举,本文重点举例说明C#枚举的用法,数字转化为枚举、枚举转化为数字及其枚举数值的判断,以下是具体的示例:先举两个简单的例子,然后再详细的举例说明:字符串转换成枚举:DayOfWeek week= (DayOfWeek)Enum.Parse(typeof(DayOfWeek), "Friday");数字转换成枚举:DayOfWeek week转载 2014-03-17 11:54:21 · 1192 阅读 · 0 评论 -
C#中的并行与多线程编程
在处理很多数据的时候,加入C#新特性的并行和任务来实现多线程,超级有趣。先说2个小代码。一个是Task任务,相当于旧版的Thread多线程。但是在.net 4.0以后都统称为Task任务了。其实就是多线程。一、Task多线程,线程结束后执行特定的代码。Task task = new Task(() =>{ //这里执行工作的主体,但是不能操作界面,会造成线程崩溃。转载 2014-03-14 13:46:13 · 8635 阅读 · 0 评论 -
通过表达示树获取属性名
public static string GetNameByExpress(Expression> expr) where T : class { var pname = ""; if (expr.Body is UnaryExpression) { var uy =原创 2014-01-10 14:48:45 · 545 阅读 · 0 评论 -
字符串中连续多个空格合并成一个空格
public string UnitMoreSpan(string str) { string originStr = str; string newStr = ""; string[] splits = originStr.Split(' '); //以空格为标志 for (原创 2013-06-18 17:10:01 · 8319 阅读 · 0 评论 -
把IP转换成数字
private static long ConvertIpToNumber(string strIpAddress) { long tmpIpNumber = 0; if (strIpAddress != null && strIpAddress.Trim() != "") {原创 2013-08-26 17:34:53 · 1948 阅读 · 0 评论 -
Twaver.net节点样式边框和背景色
node.SetStyle(Styles.INNER_STYLE, Consts.INNER_STYLE_SHAPE); //如果是INNER_STYLE_SHAPE,则显示边框 node.SetStyle(Styles.INNER_OUTLINE_PATTERN, new List() { 2, 5 }); //边框为虚线,值为NULL,则为穿线原创 2013-08-23 09:21:08 · 1916 阅读 · 0 评论 -
获取字符串的的所有数字
public string GetNums(string strt) { string strRel = ""; Match ma = Regex.Match(strt, @"([0-9]*\.{0,1}[0-9]*)"); while (ma.Success) {转载 2012-09-07 11:18:10 · 527 阅读 · 0 评论 -
C#常规操作EXCEL
使用需要添加引用: using Microsoft.Office.Interop.Excel;public class ExcelHelper { object MissingValue = Type.Missing; private Microsoft.Office.Interop.Excel.Application app = new Appl原创 2012-08-03 14:40:45 · 748 阅读 · 0 评论 -
C#.NET分别以GET和POST方式抓取远程页面
引入命名空间using System.IO;using System.Net;using System.Text;using System.Text.RegularExpressions;//以GET方式抓取远程页面内容 public string Get_Http(string tUrl) { string strResult;转载 2012-08-07 13:36:28 · 1551 阅读 · 0 评论 -
如何在C#.net中自定义和使用特性
Attribute的基本概念经常有周边人问,Attribute是什么?它有什么用?好像没有这个东东程序也能运行。实际上在.Net中,Attribute是一个非常重要的组成部分,本文整理相关资料,提供给大家参考。首先,我们肯定Attribute是一个类,下面是msdn文档对它的描述:公共语言运行时允许你添加类似关键字的描述声明,叫做attributes, 它对程序中的元素进行转载 2012-07-20 12:49:12 · 10584 阅读 · 2 评论 -
.net执行SQL脚本文件
//执行脚本文件 protected string proceedSQLScripts(string connectionString, string pathToScriptFile) { List statements = new List(); using (Stream stream = File.OpenRead(pathToScri原创 2012-03-22 15:45:46 · 725 阅读 · 0 评论 -
获取局域网内所有(数据库)SQLServer机器名和实例名
public List GetDataSource() { DataTable dataSources = SqlClientFactory.Instance.CreateDataSourceEnumerator().GetDataSources(); DataColumn column = dataSources.Columns["InstanceN转载 2012-03-22 11:48:34 · 1909 阅读 · 0 评论 -
c#程序自启动
根据网络整理:winform(c#) 开机自动启动程序public void SetAutoRun(string fileName, bool isAutoRun) { RegistryKey reg = null; try { if (!System.IO.File.Exists(fileName))转载 2010-04-25 11:01:00 · 1955 阅读 · 0 评论 -
将XML字符串转换为XML文档
public XmlDocument getXmlDocumentByStrXml(string strXml) { if (strXml != "") { XmlDocument xmlDocument = new XmlDocument(); xmlDocu原创 2012-04-01 09:16:33 · 619 阅读 · 0 评论 -
去除字符串中的HTML标签
public static string NoHTML(string strHtml) { string[] aryReg ={ @"]*?>.*?", @"", @"([\r\n]原创 2012-03-23 18:08:57 · 411 阅读 · 0 评论 -
程序操作EXCEL报错解决方法大汇总
在"开始"->"运行"中输入dcomcnfg.exe启动"组件服务" 依次双击"组件服务"->"计算机"->"我的电脑"->"DCOM配置" 在"DCOM配置"中找到"Microsoft Excel 应用程序",在它上面点击右键,然后点击"属性",弹出"Microsoft Excel 应用程序属性"对话框 点击"标识"标签,选择"交互式用户" 点击"安全"标签,在"转载 2012-09-11 16:39:51 · 995 阅读 · 0 评论 -
枚举操作
public enum AssetTypeEnum { 主机 = 1, 路由器 = 2, 交换机 = 3, 防火墙 = 4, 虚拟机 = 5 }取枚举的名称:Enum.GetName(typeof (AssetTypeEnum), 1);取枚举的数值:(int)(AssetTypeE原创 2013-08-05 16:50:41 · 459 阅读 · 0 评论 -
从字符串中提取手机号码,多个用“,”分开
/// /// 从字符串中提取手机号码,多个用“,”分开 /// /// 字符串 /// public static string IsLegalMobilePhone(String MobilePhone) { Regex myReg = new Regex(@"[原创 2013-06-20 10:03:22 · 2643 阅读 · 0 评论 -
NPOI操作excel常用方法类
using NPOI.HSSF.UserModel;using NPOI.SS.UserModel;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.IO;using System.Linq;using Sy原创 2013-06-19 17:49:02 · 3428 阅读 · 0 评论 -
c# 将richtextbox滚动条移动到最下方
//设定光标所在位置 this.RichTextBox1.SelectionStart = RichTextBox1.TextLength; //滚动到当前光标处 this.RichTextBox1.ScrollToCaret(); SelectionStart:光标起始位置,和选定不同,这时候只是定位,而非选择;转载 2013-06-18 14:43:40 · 1481 阅读 · 0 评论 -
异步的HTTP POST与GET请求例子
Get方法:private void HttpGet() { WebClient wc = new WebClient(); Uri uri = new Uri("http://localhost:3881/Financial.ashx?ticker=NTES&startdate=1-1-2009&enddate=9-2-2原创 2013-02-06 16:01:30 · 10038 阅读 · 0 评论 -
NET的类型参数约束
where T : struct | T必须是一个结构类型where T : class where T : new() | T必须要有一个无参构造函数where T : NameOfBaseClass转载 2013-01-18 09:46:25 · 476 阅读 · 0 评论 -
C#实现的图片复杂验证码
using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Text; namespace Smark.ImageNumber { ///转载 2012-12-22 12:13:04 · 2376 阅读 · 0 评论