C# 打印Assmebly里的 objects Assembly assembly = Assembly.GetAssembly(this.GetType()); Type[] types = assembly.GetTypes(); foreach(Type type in types) { ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2081浏览 2064个赞
C#生成随机ArrayList public static void RandomizeArrayList(ArrayList arrayList, Random random) { if(arrayList == null) { return; } int count = arrayList.Count; for(int i=……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1430浏览 1620个赞
这段代码演示了System.Collections.Generic的各容器类的用法,包括:Dictionary,KeyValuePair,SortedDictionary,SortedList,HashSet,SortedSet,List,Queue,Stack等类的用法System.Collections.Generic.Dictionary<……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1283浏览 2757个赞
C#中判断DataReader是否为空,下面的代码通过DataReader的HasRows属性来判断是否为空if(DataReader.HasRows){//do whatever}……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2031浏览 2787个赞
C#检测DataSet是否为空,下面的代码片段通过判断DataSet的Table数量来判断DataSet是否为空DataSet dt = new DataSet();if (dt.Tables.Count>0) // has tables in it{ //dataset is not empty}else {// otherw……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2200浏览 1226个赞
下面以链接sql server为例,默认情况下连接池的大小为100个,你可以根据需要设定连接池,下面设置为最大75个,最小5个DATA SOURCE=(LOCAL);Initial Catalog=sharejsDB;User ID=root;Password=****;Max Pool SIZE=75;Min Pool SIZE=5;……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2454浏览 813个赞
下面的代码可以实现异步发送邮件,等邮件发送出去后会自动调用回调函数,这样在发送邮件时就不会卡住程序不动了MailMessage m = new MailMessage ("item@75271.com", "raja@75271.com", "This is the subject ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1698浏览 1463个赞
C#中通过SSL发送邮件MailMessage m = new MailMessage ("item@75271.com", "raja@75271.com", "This is the subject for the authorized email.", &qu……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1676浏览 173个赞
C#中使用smtp发送邮件MailMessage m = new MailMessage ("jane@75271.com", "ben@75271.com", "This is the subject for the email.", "This is ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1776浏览 2777个赞
C#发送HTML格式的邮件MailMessage m = new MailMessage();m.From = new MailAddress("ir@w3mentor.com", "Raja Item");m.To.Add(new MailAddress("su@w3mentor.com"……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2203浏览 183个赞
C#发送带附件的邮件MailMessage m = new MailMessage();m.From = new MailAddress("ir@75271.com", "Raja Item");m.To.Add(new MailAddress("su@75271.com", "S……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1865浏览 962个赞
C#发送邮件并抄送给多个邮件接收者MailMessage m = new MailMessage();m.From = new MailAddress("ir@75271.com", "Raja Item");m.To.Add(new MailAddress("su@75271.com", ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1693浏览 1004个赞
C#读取命令行参数的代码下面的代码用于从命令行读取参数,参数个数不定,程序将会输出用户在命令行输入的所有参数列表using System; namespace W3M{ class ArgsExample { public static int Main(string[] args) { f……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2843浏览 2097个赞
C#创建、读取和修改Excelwindows下我们可以通过 Jet OLE DB访问Excel,就行访问数据库一样// Namespaces, Variables, and Constantsusing System;using System.Configuration;using System.Data; private OleDbData……继续阅读 » 水墨上仙 4年前 (2021-03-20) 3140浏览 2223个赞
C#连接ODBC数据源演示代码// Namespaces, variables, and constantsusing System;using System.Configuration;using System.Data;using System.Data.Odbc; private void CButton_Click(object se……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1310浏览 1249个赞
Asp.Net MVC中如果要通过ActionLink生成链接,传递参数可以通过下面的代码实现<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&qu……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1913浏览 1702个赞
ASP.NET MVC中通过Html.ActionLink动态生成链接C# MVC模式下HTML.ActionLink() 用于生成指定Action的丽娜姐,非常有用<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" ➥Inh……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2162浏览 2028个赞
C#通过正则表达式去除所有html标签,只要包含在里面的都会被认为是html标签string myInput="<a href=''>clean me up</a><br/>";string strippedString = Regex.Replace(myInput,@&qu……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1813浏览 1134个赞
Convert类的静态方法FromBase64String 可以讲base64编码的字符串反转为二进制数据byte[]格式,从而恢复编码后的bitmap位图byte[] imageBytes = bmpAsString.Base64DecodeString();using (FileStream fstrm = new FileStream(@&quo……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1249浏览 524个赞
C#解码base64编码的二进制数据通过在Convert类的静态方法Convert.FromBase64String,可以讲base64编码的字符串解码为等效的byte []数组。using System;static class MyModClass{public static byte[] Base64DecodeString(this st……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2105浏览 1505个赞
C#将一个bitmap位图通过base64编码成一个字符串byte[] image = null;using (FileStream filestrm = new FileStream(@"C:\mypic.bmp",FileMode.Open, FileAccess.Read)){ using (BinaryReader re……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2444浏览 732个赞
C#中对二进制数据进行base64编码using System;using System.IO;static class MyModClass{public static string Base64EncodeBytes(this byte[] inBytes){return (Convert.ToBase64String(inBytes))……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1800浏览 544个赞
C#从字符串中的指定位置移除子字符串,字符串自带remove方法可以用于删除子字符串,Remove的第一个参数为子字符串开始位置,第二个参数为要删除的子字符串长度string name = "Raja, Item";name = name.Remove(4, 1);Console.WriteLine(name); ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1703浏览 272个赞
C#查找列表中所有重复出现的元素public T[] GetDuplicates(T inputValue){ List<T> duplicates = new List<T>( ); for (int i = 0; i < this.Count; i++) { if (this[i].Equals(inputV……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2724浏览 2829个赞
这是使用linq计算元素在列表中出现的次数,调用方法非常简单,和sql语句很像// Count the number of times an item appears in this listpublic static int CountTimes<T>(this List<T> inputList, T searchItem)……继续阅读 » 水墨上仙 4年前 (2021-03-20) 3072浏览 2172个赞
C#的Array对象自带反转功能,但是下面的代码完全通过自定义的算法来实现数组反转public static void ReverseArray<T>(this T[] inputArray){ T temp = default(T); if (inputArray == null) throw new ArgumentNull……继续阅读 » 水墨上仙 4年前 (2021-03-20) 3201浏览 2383个赞
用C#自带的函数反转数组,C#的Array对象自带反转功能,代码如下int[] someArray = new int[5] {1,2,3,4,5};Array.Reverse(someArray);……继续阅读 » 水墨上仙 4年前 (2021-03-20) 3211浏览 1950个赞
C#获取文件创建时间,主要用到了FileInfo的CreattionTime属性using System;using System.IO;class Class1 { static void Main(string[] args) { string[] cla = Environment.GetCommandLineArgs(……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2707浏览 993个赞
C#返回目录的最后访问时间using System;using System.IO; class MainClass { static void Main(string[] args) { FileInfo file = new FileInfo("c:\\a.txt"); // Di……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2103浏览 1022个赞
C#从获取指定目录下的所有文件列表using System;using System.IO; class MainClass { static void Main(string[] args) { DirectoryInfo dir = new DirectoryInfo("c:\\"); ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1417浏览 2580个赞
JavaScript的Math对象包含了一个round方法用于对数字进行四舍五入操作,下面的代码详细演示了其用法<!DOCTYPE html><html><body><p id="demo">Click the button to round the number 2.5 to ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2948浏览 2956个赞
JS数组带有一个unshift方法可以再数组前面添加若干个元素,下面是详细的代码演示<!DOCTYPE html><html><body><p id="demo">Click the button to add elements to the array.</p>……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1844浏览 1581个赞
我们可以通过JS数组的splice方法在执行的位置插入新的元素,非常简单<!DOCTYPE html><html><body><p id="demo">Click the button to add elements to the array.</p><bu……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2370浏览 104个赞
JS数组的sort方法支持使用函数作为参数,下面的代码演示了JS数组如何通过sort对数字类型的数组进行倒序排序<!DOCTYPE html><html><body><p id="demo">Click the button to sort the array.</p>……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1669浏览 1299个赞
JS数组的sort方法支持一个函数作为参数,下面的代码演示了JS数组如何实现数字的正序排列<!DOCTYPE html><html><body><p id="demo">Click the button to sort the array.</p><butt……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1702浏览 488个赞
JS数组带有一个sort方法可以给数组排序,非常简单<!DOCTYPE html><html><body><p id="demo">Click the button to sort the array.</p><button onclick="my……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2395浏览 2644个赞
JS数组带有一个slice方法,可以获取数组的指定部分,下面的代码获取数组中的第二个和第三个元素<!DOCTYPE html><html><body><p id="demo">Click the button to extract the second and the third……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1501浏览 895个赞
JS中我们可以通过pop方法移除数组的最后一个元素,可以通过shift方法移除数组的第一个元素<!DOCTYPE html><html><body><p id="demo">Click the button to remove the first element of the a……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1236浏览 2856个赞
下面的代码演示了JS中如果通过数组的reverse方法将数组元素反转过来<!DOCTYPE html><html><body><p id="demo">Click the button to reverse the order of the elements in the arr……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2261浏览 2398个赞
下面的代码演示了JS数组通过push方法添加一个元素到数组末尾<!DOCTYPE html><html><body><p id="demo">Click the button to add a new element to the array.</p><bu……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2910浏览 2751个赞
下面的代码演示了JS数组的pop方法,可以用来移除数组的最后一个元素,实际上就是把数组当成堆栈使用<!DOCTYPE html><html><body><p id="demo">Click the button to remove the last array element.&……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2213浏览 2325个赞
下面的代码演示了JS中如何通过contact函数链接多个数组<!DOCTYPE html><html><body><script>var parents = ["Jani", "Tove"];var brothers = ["Stale&quo……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2219浏览 1791个赞
下面的JS代码输出全部的cookie键值对照<!DOCTYPE html><html><body>Cookies associated with this document: <script>document.write(document.cookie);</script>&l……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1941浏览 1033个赞
下面的JS代码通过document.links获得网页中的所有超级链接数组,然后获得第一个链接的ID属性<!DOCTYPE html><html><body><h1>75271.com</h1><img src ="planets.gif" width=&quo……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2625浏览 2130个赞
下面的JS代码通过document.links获取网页中的所有超级链接,从而获得超级链接的数量<!DOCTYPE html><html><body><img src ="planets.gif" width="145" height="126" ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2414浏览 885个赞