这段C#代码可以从http://www.time.ac.cn网站上获取标准的北京时间,只需简单的组合即可让本地服务器实时同步正确的北京时间 #region /// <summary> /// 获取标准北京时间 /// /// </summary&g……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2484浏览 619个赞
通过Timer可以定期调用指定的代码,C#中的Timer可以每隔几秒或者几分钟定期指定一个指定的函数。如果我们需要定时监控重要程序的状态或者变量状态都非常有用。Timer被定义在System.Timers命名空间内。举例:下面这个C#范例是定义了一个静态类,这意味着它不能有实例成员或字段。它包括System.Timers命名空间,它定义了一个定时执行的函……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1897浏览 1737个赞
C#使用基姆拉尔森算法计算指定日期是星期几基姆拉尔森计算公式W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7在公式中d表示日期中的日数,m表示月份数,y表示年数。注意:在公式中有个与其他公式不同的地方:把一月和二月看成是上一年的十三月和十四月,例:如果是2004-1-10则换算成:2003-13-10来代入公……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2400浏览 188个赞
C#内置的日期类是在是太强大了,很多东西根本不需要我们自己去编写,这里计算当前日期是星期几,C#不用基姆拉尔森算法很简单就可以获得。//获取当前日期是星期几string dt = DateTime.Today.DayOfWeek.ToString();protected string GetWeek(string dt){ string……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1593浏览 1050个赞
C#连接两个数组的函数代码,数组的元素类型任意,将第二个数组连接到第一个数组的后面 T[] Concat<T>(params T[][] arrays){ List<T> output = new List<T>(); for(int i = 0; i < arrays.Length; i++)……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2825浏览 1164个赞
这段代码很简单的将unix时间戳转换成容易阅读的DateTime对象,原理很简单,先获得1970年1月1日的DateTime对象,然后加上你的时间戳的秒数即可。DateTime epoch = new DateTime(1970,1,1,0,0,0,0, DateTimeKind.Utc);DateTime myDate = epoch.AddSec……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2731浏览 2482个赞
给出用户的出生日期,计算出用户的年龄,C#代码简单实用public int CalculateAgeCorrect(DateTime birthDate, DateTime now){ int age = now.Year - birthDate.Year; if (now.Month < birthDate.Month || ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2356浏览 1566个赞
有时候网站通过nginx作为前端反向代理,这样后端直接获取ip地址就是代理服务器的IP地址,一般是一个内网IP,下面这段代码可以帮助你获取访客的真实IP地址,当然必须nginx前端做了相应的参数传递处理。 static public string GetClientIP() { string result = Htt……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3408浏览 2709个赞
C#自定义字符串压缩和解压缩代码库class ZipLib { public static string Zip(string value) { //Transform string into byte[] byte[] byteArray = new byte……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2150浏览 888个赞
C#对字符串进行压缩和解压缩的算法代码,字符串通过base64编码后传输代码转自:http://www.cnblogs.com/luoxiaojie/public class Compression { /// <summary> /// 对字符串进行压缩 /// </summ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3078浏览 348个赞
C#对list列表进行随机排序public List<T> RandomSortList<T>(List<T> ListT){ Random random = new Random(); List<T> newList = new List<T>(); foreach……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2906浏览 754个赞
C#扩展String类,自定义ToFormat方法格式化字符串,可以以string.ToFormat的形式格式化字符串,使用非常方便using System;public class Example{ public static string ExampleString = "Hello {0}".ToFormat(&……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3076浏览 1334个赞
C#通过StreamWriter和StreamReader写入和读取文件/*C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002)ISBN: 0072134852*/// Demonstrate String……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2501浏览 886个赞
在Razor中使用for each语句和后端C#代码类似,更容易遍历输出html内容<html><body><ul>@foreach (var x in Request.ServerVariables) {<li>@x</li>}</ul></body>……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1970浏览 1756个赞
在Razor页面中使用for循环语句和在后端的C#代码使用for循环语句没有什么区别,但是在页面里面for循环语句可以输出更多html格式的内容,非常方便,无需使用Response.Write的方式<html><body>@for(var i = 10; i < 21; i++){<p>Line @i&……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3184浏览 162个赞
C#自定义繁体和简体字库实现中文繁体和简体之间的转换,由于需要自定义繁体和简体的一对一字库,所以代码会比较长代码转自:http://blog.csdn.net/mypc2010/using System;using System.Collections.Generic;using System.Linq;using System.Text;u……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1491浏览 2631个赞
一个C#实现异步调用的简单范例代码代码转自:http://blog.csdn.net/mypc2010//* * User: MXi4oyu * Email:798033502@qq.com * Date: 2013-7-18 * Time: 19:50 * */using System;using System.Threading……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2754浏览 2319个赞
SqlHelper其实是我们自己编写的一个类,使用这个类目的就是让使用者更方便、更安全的对数据库的操作,既是除了在SqlHelper类以外的所有类将不用引用对数据库操作的任何类与语句,无须担心数据库的连接与关闭的问题。转自:http://blog.csdn.net/dandanzmc/article/details/9345937{ ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1957浏览 525个赞
C#操作PowerPoint的基本代码,包括打开ppt文件、读取幻灯页,插入幻灯片,自动播放等using System;using System.Collections.Generic;using System.Linq;using System.Text;using OFFICECORE = Microsoft.Office.Core;us……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2708浏览 1854个赞
这个C#类包含了各种常用数据验证的函数,包含验证是否是数字,校验email格式,区分中英文截取字符串,区分中英文计算字符串长度,检测是否包含中文字符,判断是否包含特定字符等using System;using System.Text;using System.Web;using System.Web.UI.WebControls;using S……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3137浏览 1052个赞
c#生成注册码using System;using System.Management;using System.Security.Cryptography;using System.IO;using System.Collections.Generic;using System.Text;namespace xingming_reg{……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1835浏览 1976个赞
c#简单分页using System;using System.Collections.Generic;using System.Text;namespace WindowsApp{ class Paging { private int rowsPerPage; //每页显示的记录数 priv……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2694浏览 2390个赞
C#操作sqlite(包含中文支持)using System;using System.Data;using System.Text.RegularExpressions;using System.Xml;using System.IO;using System.Collections;using System.Data.SQLite;……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2735浏览 1971个赞
一个简单的C#多线程间同步的例子using System;using System.Collections;using System.Collections.Generic;using System.Threading;////// 在开发中经常会遇到线程的例子,如果某个后台操作比较费时间,我们就可以启动一个线程去执行那个费时的操作,同时程……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2038浏览 960个赞
C#常用操作1. StreamWriter - 文件写入类StreamWriter s = new StreamWriter(address + "/Menu.ini", true);s.WriteLine(openFileDialog1.FileName);s.Flush();s.Close();2. StreamRe……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2745浏览 2865个赞
VC中提供了API函数进行INI文件的读写操作,但是微软推出的C#编程语言中却没有相应的方法,下面是一个C# ini文件读写类,从网上收集的,很全,就是没有对section的改名功能。using System;using System.IO;using System.Runtime.InteropServices;using System.Tex……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1973浏览 689个赞
C# 实现的 AES 加密算法using System;using System.IO;using System.Security.Cryptography; //// Sample encrypt/decrypt functions// Parameter checks and error handling// are ommited ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1573浏览 543个赞
C#操作SQL Server通用类using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Collections;using System.Data.SqlClient;……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2453浏览 2817个赞
C# 连接 MySQL 数据库的代码using System;using System.Data; class MySqlConnect { static void Main() { string connString = @"Data Source=server;Database=……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3265浏览 1372个赞
没有返回值,没有参数传递。MySqlConnection myConnection; myConnection = new MySqlConnection();myConnection.ConnectionString = "database="+database+";server="+ se……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1592浏览 1184个赞
C#实现的字符串加密和解密方法public class Encrypt{//默认密钥向量private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; /// <summary>/// DES加密字符串/// </su……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1981浏览 2577个赞
C#实现写入文本文件内容功能private void write_txt(string str1, string str2, string str3){ System.DateTime currentTime = System.DateTime.Now; string strYMD = currentTime.ToString(&qu……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2818浏览 2355个赞
需要mysql.data.dllusing System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;using System.Data;using System.Text.RegularExpressions;///using……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2851浏览 309个赞
c# 简单的系统管理命令using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Diagnostics;using System.Runtime.InteropS……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3395浏览 129个赞
C#编写的FTP上传简单工具类using System;using System.Net;using System.IO;using System.Text;using System.Net.Sockets;using System.Collections;using System.Collections.Generic;namespac……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2919浏览 1031个赞
C#目录内文件批量查找替换字符串内容using System;using System.Collections.Generic;using System.Text;using System.Text.RegularExpressions;using System.IO;public class MyClass{ public st……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2601浏览 2942个赞
这个C#类封装的DES加密解密,可以使用默认秘钥进行加密、解密,也可以自定义秘钥进行加密、解密,调用简单方便。using System;using System.Security.Cryptography; using System.Text;namespace DotNet.Utilities{ /// <summary> ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3274浏览 2851个赞
C#图片剪裁类public class ImageCut{ /// <summary> /// 剪裁 -- 用GDI+ /// </summary> /// <param name="b">原始Bitmap</param> /// <pa……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2516浏览 487个赞
c#九九乘法表using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Multiplication{ class Program { static void Main(string[]……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2809浏览 2482个赞
C#统计目录中文件MD5值,并存入剪贴板中using System.IO;using System.Security.Cryptography;using System.Collections;using System.Windows.Forms; IDataObject iData = Clipboard.GetDataObject(); ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1785浏览 1789个赞
C#除去以//开始的注释using System.IO; using System.Collections; static string deleteComments(string s) //去掉以//开始的注释 { if (s == null) return s; int pos = s.In……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1677浏览 1287个赞
C#解压缩单个zip格式文件using System.IO;using System.IO.Compression;string sourceFile=@"D:\2.zip";string destinationFile=@"D:\1.txt"; private const long BUFFER……继续阅读 » 水墨上仙 5年前 (2021-03-12) 3099浏览 2350个赞
C#压缩单个zip格式文件using System.IO;using System.IO.Compression;string sourceFile=@"C:\1.txt";string destinationFile=@"D:\2.zip"; private const long BUFFER_SIZE……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2597浏览 261个赞
C# 字符串数组转换为整形数组/// <summary>/// 字符串数组转换整形数组/// </summary>/// <param name="Content">字符串数组</param>/// <returns></returns>public ……继续阅读 » 水墨上仙 5年前 (2021-03-12) 2876浏览 2788个赞
c#打开网页using System.Diagnostics;Process.Start(@"C:\Program Files\Internet Explorer\iexplore.exe", "http://ant.sourceforge.net/");……继续阅读 » 水墨上仙 5年前 (2021-03-12) 1747浏览 1918个赞