2009年12月小记(Split,netstat,SortedList)

买家面对面 

瑞雅商城

瑞雅淘宝 

1、string.Split

string str = "abc$$123$4$5";
string[] strs = str.Split(new string[] { "$$" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in strs)
{
  Response.Write(s + "<hr />");
}

 2、查看指定端口号连接情况

netstat -abn | find "8800" 

3、SortedList

代码
        SortedList<intint> list = new SortedList<intint>(100);
        
for (int i = 0; i < 100; i++)
        {
            list.Add(i, i 
+ 1000);
        }
        list.TrimExcess();

        
for (int i = 80; i < 120; i++)
        {
            Response.Write(
string.Format("InternalID={0}, IndexOfKey={1} <br/>", i, list.IndexOfKey(i)));
            
int userid = 0;
            list.TryGetValue(i, 
out userid);//userid不存在会返回0
            Response.Write(string.Format("InternalID={0}, UserId={1} <br/>", i, userid));
            Response.Write(
"<hr />");
        }

 代码

        SortedList<intint> list = new SortedList<intint>(100);
        
for (int i = 0; i < 100; i++)
        {
            
//由小到大排序
            list.Add(Guid.NewGuid().ToString().GetHashCode(), i);
        }
        list.TrimExcess();

        
foreach (KeyValuePair<intint> kv in list)
        {
            Response.Write(
string.Format("{0}, {1}", kv.Key, kv .Value));
            Response.Write(
"<hr />");
        }
原文地址:https://www.cnblogs.com/chenjunbiao/p/1760301.html