C# 删除一维数组内的某个值(元素), C# 删除数组元素的方法
static void Main(string[] args)
{// 声明一维数组int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };// 数组转换为集合List<int> list = arr.ToList
C# 如何判断一个字符串是否包含另一个字符串的方法,C# IndexOf 的使用static void Main(string[] args)
{string str = "Hello Word";string a = "e";if (str.IndexOf(a) >= 0){Console.WriteLine("存在指定字符串.")
Winform 只能输入整数的TextBox (文本框) 控件using System;
using System.Windows.Forms;namespace DemoWinForm
{public partial class Form1 : Form{public Form1(){InitializeComponent();}}/// <summary>/// 文本
Winform 禁止重复启动,单实例exe程序修改"Program.cs"文件using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;namespace WindowsFormsApp5
{static class Progra
添加"KeyPress"事件
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{e.Handled = true;
}
C# ashx页面获取URL参数后台获取代码public void ProcessRequest(HttpContext context)
{context.Response.ContentType = "text/plain";context.Response.Write("Hello World");// 当前页面完整URL为:http://www.hic
C# 百分比转数字,百分比转换为小数static void Main(string[] args)
{string percent = "25%";double number = double.Parse(percent.Replace("%", "")) / 100;Console.WriteLine(percent + ":" + number);Console.R
C# List取交集, List取交集的方法// using System.Linq;static void Main(string[] args){// Intersect 交集// Except 差集// Union 并集List<int> list1 = new List<int> { 1, 2, 3, 4, 5 };List<int> list2 = new L
C# string字符串转Guidstatic void Main(string[] args)
{string str = "BC9F772B-38AA-447C-B2E3-D7A4D55E2796";//string str = "{BC9F772B-38AA-447C-B2E3-D7A4D55E2796}";// 方式1Guid g1 = new Guid(str);// 方式
C# 16进制字符串转换byte[]数组static void Main(string[] args)
{// 16进制字符串, 0x000000000002654Dstring str = "000000000002654D";// 或者 02654D// 16进制字符串 -> bytesbyte[] a = BytesToHexString(str);/
C# 如何将string字符串转换为Base64字符串
public static void Main()
{// 将string字符串转换Base64字符串string str = "Hello Word";byte[] bytes = Encoding.UTF8.GetBytes(str);string base64Str = Convert.ToBas
C# 获取任意日期的前一天日期,后一天日期
// 获取指定日期
DateTime dateTime = DateTime.Now;// 获取指定日期的前一天
DateTime prevDateTime = DateTime.Now.AddDays(-1);// 获取指定日期的后一天
DateTime nextDa
DataGridView 绑定时间类型数据格式化输出方法
dataGridView1.Columns["创建时间"].DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss";
Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似key/value的键值对,所以Hashtable可以支持任何类型的key/value键值对。
一,哈希表(Hashtable)简述在.NET Framework中,Hashtable是System.
C# 实现字符串文本换行的方法,文本如何换行
static void Main(string[] args)
{Console.WriteLine(WrapText("HelloWord", 2));Console.Read();
}/// <summary>
/// 字符串文本换行
/// <para>
/// eg:WrapText("Hell
添加一个类文件"BaseForm.cs"代码如下:using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;namespace
DataReader对象提供了用顺序的,只读的方式读取Command对象获得的数据结果集,正是因为DataReader是以顺序的方式连续的读取数据,所有DataReader会以独占的方式打开数据库的连接,由于DataReader只执行读的操作(只读
ASP.NET性能优化建议包括以下几点数据库访问性能优化,字符串操作性能优化,禁用调试模式等等,感兴趣的盆友可以参考下。1、数据库访问性能优化
(1).尽量减少数据库连接,并充分利用每次数据库连接:连接的创建、打开
1. 使用场景 适用于服务器功能不强的web站点,不希望频繁通过读取数据库来展示内容,当有新的内容产生时,生成静态页面存放内容,数据库中只保留如标题,类别等一些查询关键字。2. 使用静态页面的好处
(1)提高网站的
C# 获取某文件夹下的所有文件的文件名的方法
static void Main(string[] args)
{DirectoryInfo di = new DirectoryInfo(@"E:\Work\Demo");FindFile(di);Console.Read();
}static void FindFile(DirectoryInfo di)
{Fi
标识符(Identifier)是适用于变量、类、方法和其他各种用户定义对象的一般术语。
在编写代码时遵循命名规则,可以让程序更加易懂、易读;而且还能提供它的功能信息,如它是否是一个常量、包名或类等,这都有助于对
C# 控制台窗体退出事件 Console Exit
static void Main(string[] args)
{AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);
}static void OnProcessExit(object sender, EventArgs e)
{Conso
1.using 指令using 命名空间名字,这样可以在程序中直接用命令空间中的类型,而不必指定类型的详细命名空间,类似于Java的import,这个功能也是最常用的,几乎每个cs的程序都会用到。例如:using System;
using Syste
后台获取代码
// 当前页面完整URL为:http://www.hicsharp.com/index.aspx?keyword=test&page=1// 1.获取页面完整的URL,协议名+域名+站点名+文件名+参数
string url = Request.Url.ToString() ;
// 结果:http://ww
C# 去掉最后一个字符,如何删除或移除字符串最后一个字符static void Main(string[] args)
{string str = "测试删除字符串最后一个字符";if (!string.IsNullOrEmpty(str)){// 删除最后一个字符string strSub = str.Su
bool.parse 只能对文本对象进行转换,而且只能是 true or false, 不区分大小写Convert.ToBoolean 方法可以对文本、数值对象进行转换 0->false, 非0->truestatic void Main(string[] args)
{string a = "true";bool b1
C# get 网址时出现异常“The underlying connection was closed: An unexpected error occurred on a send”static void Main(string[] args)
{try{string str = GetData("https://www.abc.com");}catch (WebExceptio
.NET在支持 TLS 1.1 或 TLS 1.2 操作系统中运行时,兼容最新版本.NET 4.6 和更高版本
兼容 TLS 1.1 或更高版本(默认设置)。.NET 4.5 至 4.5.2
默认情况下,.NET 4.5、4.5.1 和 4.5.2 场合, TLS 1.1 和 TLS1.2有效,
若event不为null,则invoke,这是C#6的新语法。 ?.称为空值传播运算符。// C# 5
var handler = Event;
if (handler != null)
{ handler(source, e);
}// C# 6
var handler = Event;
handler?.Invoke
C# decimal 去掉多余的0, 输出文本只保留小数数字部分static void Main(string[] args)
{decimal price = 3.14000m;Console.WriteLine(price.ToString("0.#####"));// output: 3.14Console.Read();
}
C# 多线程锁,写入文件防止被其他线程占用
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;names
C# IP与整数之间的相互转换, ip to long1、IP地址转换为整数原理:IP地址每段可以看成是8位无符号整数即0-255,把每段拆分成一个二进制形式组合起来,然后把这个二进制数转变成一个无符号的32位整数。举例:一个ip地址
用"ORDER BY NEWID()"进行随机排序
USE TestDB;
GOSELECT * FROM [Users] ORDER BY NEWID();
js 判断是否为手机端、移动端访问
<!DOCTYPE html><html>
<head><meta charset="utf-8" /><script type="text/javascript" src="/js/jquery-1.4.1.min.js"></script><script type="text/javascript">(function () {va
Visual Studio, C# 程序集信息 AssemblyInfo.cs 文件详解
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;// 有关程序集的常规信息通过以下
// 特性集控制。
HTML 5
<!DOCTYPE html>HTML 4.01 Strict 该 DTD 包含所有 HTML 元素和属性,但不包括展示性的和弃用的元素(比如 font)。不允许框架集(Framesets)。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http:/
css 控制内容字母自动转换大小写, 控制大小写字母自动转换
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w
C# 创建、保存、写入无 bom 的 utf-8 编码文件static void Main(string[] args){// 方式一System.Text.UTF8Encoding utf8 = new System.Text.UTF8Encoding(false);using (StreamWriter sr = new StreamWriter("D:\\te
ASP.NET aspx 后台代码执行前台js脚本, 弹出消息, 调用函数protected void button1_Click(object sender, EventArgs e){// 设置按钮可用RegisterStartupScript("", "");// 弹出提示Response.Write(" ");Page.ClientSc
前台代码内容后台代码// 隐藏protected void Button1_Click(object sender, EventArgs e){//// 方式一RegisterStartupScript("", "");// 方式二Page.ClientScript.RegisterStartupScript(this.GetType(), "", "");}//
js 打印功能打印测试function printDocument() {document.all.btnPrint.style.display = 'none';window.print();document.all.btnPrint.style.display = '';}打印测试1打印测试2打印测试3打印
vs2010 编辑项目时,尤其是Winform项目会在在项目所在的磁盘中会生成类似乱码的文件夹解决方案:将项目移动到英文路径下,问题解决。
css 设置图片平铺
background:url('images/1.gif') no-repeat; /*不平铺*/
background:url('images/2.gif') repeat-x; /*横向平铺*/
background:url('images/3.gif') repeat-y; /*纵向平铺*/
参数按址传递需要用到 ref 关键字,ref 标识的参数可以改变参数的原始值。static void Main(string[] args){string a = "0";int b = 0;Console.WriteLine("调用函数前");Console.WriteLine("a: {0}",a);Console.Write
C# 通过循环的方式遍历数组中不相同的元素static void Main(string[] args){int[] arrA = { 1, 2, 3, 4, 5, 9 };int[] arrB = { 1, 4, 5, 7, 8, 9 };string result = "";// arrA中的元素不再arrB中的结果foreach (int
字段格式化代码
DataBinder.Eval(Container.DataItem,"CreateTime","{0:yyyy-MM-dd HH:mm}")
js 获取 url 参数//var url = parent.location.search;var url = " http://www.abc.com.cn/index.asp?aa=1&bb=2&cc=3";var request = new Object();if (url.indexOf("?") != -1)// 参数前的地址{var str = url.subs
ASP.NET 2.0 中新增了属性"MaintainScrollPositionOnPostback",该值为"true"时页面发生PostBack后滚动条的位置不变。页面设置