这段代码演示了System.Collections.Generic的各容器类的用法,包括:Dictionary,KeyValuePair,SortedDictionary,SortedList,HashSet,SortedSet,List,Queue,Stack等类的用法System.Collections.Generic.Dictionary<……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1719浏览 2421个赞
C#中判断DataReader是否为空,下面的代码通过DataReader的HasRows属性来判断是否为空if(DataReader.HasRows){//do whatever}……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2787浏览 1537个赞
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) 2376浏览 884个赞
下面以链接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) 1366浏览 1499个赞
下面的代码可以实现异步发送邮件,等邮件发送出去后会自动调用回调函数,这样在发送邮件时就不会卡住程序不动了MailMessage m = new MailMessage ("item@75271.com", "raja@75271.com", "This is the subject ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2469浏览 1715个赞
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) 1216浏览 1369个赞
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) 2861浏览 1836个赞
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) 1768浏览 1845个赞
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) 1671浏览 1038个赞
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) 1470浏览 760个赞
C#读取命令行参数的代码下面的代码用于从命令行读取参数,参数个数不定,程序将会输出用户在命令行输入的所有参数列表using System; namespace W3M{ class ArgsExample { public static int Main(string[] args) { f……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2907浏览 1116个赞
C#创建、读取和修改Excelwindows下我们可以通过 Jet OLE DB访问Excel,就行访问数据库一样// Namespaces, Variables, and Constantsusing System;using System.Configuration;using System.Data; private OleDbData……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1943浏览 1172个赞
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) 2064浏览 354个赞
Asp.Net MVC中如果要通过ActionLink生成链接,传递参数可以通过下面的代码实现<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&qu……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2318浏览 1059个赞
ASP.NET MVC中通过Html.ActionLink动态生成链接C# MVC模式下HTML.ActionLink() 用于生成指定Action的丽娜姐,非常有用<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" ➥Inh……继续阅读 » 水墨上仙 4年前 (2021-03-20) 3096浏览 2251个赞
C#通过正则表达式去除所有html标签,只要包含在里面的都会被认为是html标签string myInput="<a href=''>clean me up</a><br/>";string strippedString = Regex.Replace(myInput,@&qu……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2913浏览 878个赞
Convert类的静态方法FromBase64String 可以讲base64编码的字符串反转为二进制数据byte[]格式,从而恢复编码后的bitmap位图byte[] imageBytes = bmpAsString.Base64DecodeString();using (FileStream fstrm = new FileStream(@&quo……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1531浏览 731个赞
C#解码base64编码的二进制数据通过在Convert类的静态方法Convert.FromBase64String,可以讲base64编码的字符串解码为等效的byte []数组。using System;static class MyModClass{public static byte[] Base64DecodeString(this st……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2693浏览 2155个赞
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) 3216浏览 2392个赞
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) 2088浏览 2026个赞
C#从字符串中的指定位置移除子字符串,字符串自带remove方法可以用于删除子字符串,Remove的第一个参数为子字符串开始位置,第二个参数为要删除的子字符串长度string name = "Raja, Item";name = name.Remove(4, 1);Console.WriteLine(name); ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2262浏览 390个赞
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) 1959浏览 2365个赞
这是使用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) 1922浏览 2338个赞
C#的Array对象自带反转功能,但是下面的代码完全通过自定义的算法来实现数组反转public static void ReverseArray<T>(this T[] inputArray){ T temp = default(T); if (inputArray == null) throw new ArgumentNull……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2797浏览 198个赞
用C#自带的函数反转数组,C#的Array对象自带反转功能,代码如下int[] someArray = new int[5] {1,2,3,4,5};Array.Reverse(someArray);……继续阅读 » 水墨上仙 4年前 (2021-03-20) 3235浏览 1020个赞
C#获取文件创建时间,主要用到了FileInfo的CreattionTime属性using System;using System.IO;class Class1 { static void Main(string[] args) { string[] cla = Environment.GetCommandLineArgs(……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2683浏览 372个赞
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) 2271浏览 2913个赞
C#从获取指定目录下的所有文件列表using System;using System.IO; class MainClass { static void Main(string[] args) { DirectoryInfo dir = new DirectoryInfo("c:\\"); ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1707浏览 2839个赞
JavaScript的Math对象包含了一个round方法用于对数字进行四舍五入操作,下面的代码详细演示了其用法<!DOCTYPE html><html><body><p id="demo">Click the button to round the number 2.5 to ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2057浏览 594个赞
JS数组带有一个unshift方法可以再数组前面添加若干个元素,下面是详细的代码演示<!DOCTYPE html><html><body><p id="demo">Click the button to add elements to the array.</p>……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1510浏览 2714个赞
我们可以通过JS数组的splice方法在执行的位置插入新的元素,非常简单<!DOCTYPE html><html><body><p id="demo">Click the button to add elements to the array.</p><bu……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2641浏览 591个赞
JS数组的sort方法支持使用函数作为参数,下面的代码演示了JS数组如何通过sort对数字类型的数组进行倒序排序<!DOCTYPE html><html><body><p id="demo">Click the button to sort the array.</p>……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2183浏览 799个赞
JS数组的sort方法支持一个函数作为参数,下面的代码演示了JS数组如何实现数字的正序排列<!DOCTYPE html><html><body><p id="demo">Click the button to sort the array.</p><butt……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2479浏览 1617个赞
JS数组带有一个sort方法可以给数组排序,非常简单<!DOCTYPE html><html><body><p id="demo">Click the button to sort the array.</p><button onclick="my……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2060浏览 727个赞
JS数组带有一个slice方法,可以获取数组的指定部分,下面的代码获取数组中的第二个和第三个元素<!DOCTYPE html><html><body><p id="demo">Click the button to extract the second and the third……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2059浏览 1281个赞
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) 2019浏览 677个赞
下面的代码演示了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) 2545浏览 1906个赞
下面的代码演示了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) 2386浏览 1074个赞
下面的代码演示了JS数组的pop方法,可以用来移除数组的最后一个元素,实际上就是把数组当成堆栈使用<!DOCTYPE html><html><body><p id="demo">Click the button to remove the last array element.&……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2744浏览 1993个赞
下面的代码演示了JS中如何通过contact函数链接多个数组<!DOCTYPE html><html><body><script>var parents = ["Jani", "Tove"];var brothers = ["Stale&quo……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2207浏览 2715个赞
下面的JS代码输出全部的cookie键值对照<!DOCTYPE html><html><body>Cookies associated with this document: <script>document.write(document.cookie);</script>&l……继续阅读 » 水墨上仙 4年前 (2021-03-20) 2493浏览 316个赞
下面的JS代码通过document.links获得网页中的所有超级链接数组,然后获得第一个链接的ID属性<!DOCTYPE html><html><body><h1>75271.com</h1><img src ="planets.gif" width=&quo……继续阅读 » 水墨上仙 4年前 (2021-03-20) 3057浏览 603个赞
下面的JS代码通过document.links获取网页中的所有超级链接,从而获得超级链接的数量<!DOCTYPE html><html><body><img src ="planets.gif" width="145" height="126" ……继续阅读 » 水墨上仙 4年前 (2021-03-20) 3104浏览 2635个赞
下面的代码通过document.images获取网页中的所有图片,然后获取第一个图片的id属性<!DOCTYPE html><html><body><img id="klematis lilac" border="0" src="klematis.jpg&……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1410浏览 1772个赞
下面的JS代码通过document.forms数组获取网页中的表单,并返回第一个表单的name属性,即名字<!DOCTYPE html><html><body><h1>75271.com</h1><form name="Form1"></form&g……继续阅读 » 水墨上仙 4年前 (2021-03-20) 1902浏览 2628个赞