惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
Intezer
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
N
News | PayPal Newsroom
T
Tenable Blog
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
P
Privacy International News Feed
IT之家
IT之家
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
博客园_首页
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
NISL@THU
NISL@THU
I
InfoQ
D
DataBreaches.Net
有赞技术团队
有赞技术团队
K
Kaspersky official blog
Security Latest
Security Latest
The Register - Security
The Register - Security
Hugging Face - Blog
Hugging Face - Blog
S
Security @ Cisco Blogs
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
AI
AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic

博客园 - 亦续缘

[CSS]textarea设置下划线格式 赠送google wave邀请函 int[] 和 string[] 互换 - 亦续缘 Web可用性设计的247条指导方针 line-height和字体实际高度的计算 IIS7用进程池的PID查找占用CPU的站点 UNICODE与汉字编码互转 CSS中属性的书写顺序 TinyMCE在线编辑器用JavaScript取值的问题 给SQL数据库表和字段添加描述信息 javascript 正确截取单字节和双字节混和字符串的方法 - 亦续缘 - 博客园 DataTable转换成JSON字符串的函数 异常详细信息: 不能通过已删除的行访问该行的信息 Web开发利器之IEWebDeveloperV2--有注册码 HttpUtility.ParseQueryString直接从字符串URL中提取参数 JavaScript创建命名空间 JavaScript ColorDropDownList - 亦续缘 - 博客园 asp.net Forms验证跨域页面不能访问的问题 语音验证码
将字符串转换成List<T> - 亦续缘 - 博客园
亦续缘 · 2009-08-04 · via 博客园 - 亦续缘

将字符串按指定的分隔符转换成List<T>类型,但目前只支持int和string,如果哪位有更好的方法希望不吝赐教,欢迎大家拍砖。直接上代码:

/// <summary>

/// 将字符串转换成List<T>

/// </summary>

/// <typeparam name="T">类型,目前只支持int,string</typeparam>

/// <param name="str">要转换的字符串</param>

/// <param name="split">分隔符</param>

/// <returns></returns>

public static List<T> ToList<T>(this string str, string split)

{

    if (!string.IsNullOrEmpty(str))

    {

        string[] arr = str.Split(new char[] { Convert.ToChar(split) });

        if (typeof(T) == typeof(int))

        {

            //int[] arri = Array.ConvertAll(arr, new Converter<string, int>(StrToInt));

            int[] arrInt = Array.ConvertAll<string, int>(arr, delegate(string s) { return int.Parse(s); });

            List<int> list = new List<int>(arrInt);

            return list as List<T>;

        }

        else if (typeof(T) == typeof(string))

        {

            List<string> list = new List<string>(arr);

            return list as List<T>;

        }

        else

        {

            return new List<T>();

        }

     }

     else

     {

         return new List<T>();

     }

}