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

推荐订阅源

W
WeLiveSecurity
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
S
SegmentFault 最新的问题
V2EX - 技术
V2EX - 技术
Hacker News: Ask HN
Hacker News: Ask HN
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
U
Unit 42
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
H
Help Net Security
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Heimdal Security Blog
博客园 - 聂微东
S
Securelist
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
Cisco Talos Blog
Cisco Talos Blog

博客园 - 亦续缘

[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>();

     }

}