C#常用方法总结

1、在循环套循环的方法里面(导致执行很慢),将数据存到内存里面进行计算,优化速度

var numResultDataTable = new DataTable();

var thisNumDataView = numResultDataTable.AsDataView();

// 注释:取出DataView中psn为item的视图,然后再转换为DataTable

thisNumDataView.RowFilter = $"psn = {item?.ToString().Replace("\"","")}";

var thisPsnNumDataTable = thisNumDataView.ToTable();

2、c#字符串切割split使用方法

string agentInfo = userInfo.Attribute19.ToString();
string[] myAgent = agentInfo.Split(new string[] { "$#$" }, StringSplitOptions.None);
if (myAgent.Length == 3)
{
    this.QLookUpMyAgent.Text = myAgent[0].ToString();
    this.QCalenderStartDate.Value = myAgent[1].ToString();
    this.QCalenderEndDate.Value = myAgent[2].ToString();
}

3、项目证书过期

a、项目里面更新

b、编译环境更新

C:\Windows\Microsoft.NET\Framework64\v4.0.30319

c、iis更新

C:\WINDOWS\system32\inetsrv

d、vs2017属性,所属目录,更换

4、数字以及字母的正则表达式

var reg1 = Regex.IsMatch(password, @"[a-zA-Z]");
var reg2 = Regex.IsMatch(password, @"[0-9]");
var reg3 = Regex.IsMatch(password, @"^[a-zA-Z0-9]*$");

5、从富文本中提取出纯文本的方法

public static string GetHtmlText(string html)
{
    html = System.Text.RegularExpressions.Regex.Replace(html, @"<\/*[^<>]*>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    html = html.Replace("\r\n", "").Replace("\r", "").Replace("&nbsp;", "").Replace(" ", "");
    return html;
}

 

6、session基础用法

//session赋值,以及取值
Session["userName"] = "aaa";
string str = Session["userName"].ToString();
//清除数据
Session["UserName"] = null;

7、smtp发送邮件,失败也不报错

原因可能是邮件的收件方将端口封锁了,可以切换其他端口发送(587)

8、返回与指定虚拟路径相对应的物理路径

Server.MapPath("~/upload/" + fileName)

9、声明数组

long[,] a = new long[5,6];
a[0,1] = 1;

int[,] cArr = new int[,] { { 1, 2 }, { 2, 2 } };

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值