Skip to content

Instantly share code, notes, and snippets.

@kurokuru
Created September 10, 2021 06:15
Show Gist options
  • Save kurokuru/ba55204cfdb870209165a94355b13edc to your computer and use it in GitHub Desktop.
Save kurokuru/ba55204cfdb870209165a94355b13edc to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
public class Hello{
public static void Main(){
// Your code here!
int value = 1234; // value > 0 を満たさないといけない
var digit = Enumerable.Range(0, (int)Math.Log10(value) + 1) // 常用対数で桁を求め
.Select((item, index) => index) // インデックス番号を値に入れて
.Select(d => (int)(value / (long)Math.Pow(10,d) % 10)); // その桁の整数値を求める
// UIの表示とかにはこのままのほうが扱いやすい
Console.WriteLine(String.Join(",", digit));
// 単純に桁毎に配列に分ける場合はReverse()する
Console.WriteLine(String.Join(",", digit.Reverse()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment