0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【C#】文字列、整数の型切り替え

Last updated at Posted at 2021-02-27

一括でまとめいているサイトがなかったのでメモ。

単なる変換

###文字列 → 整数

string s = "1";
int i = int.Parse(s);

###整数 → 文字列

int i = 2;
string s = i.ToString();

#リストの変換
###文字列 → 整数

参考サイト:stackoverflow - How to convert List to List?

List<string> ls = new List<string>() {"1", "2", "3"};
List<int> li = ls.Select(int.Parse).ToList();

###整数 → 文字列

参考サイト:stackoverflow - Cast List to List in .NET 2.0

List<int> li = new List<int>(new int[] { 1,2,3 } );
List<string> ls = li.ConvertAll<string>(x => x.ToString());
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?