LoginSignup
5
6

More than 5 years have passed since last update.

C#でRubyっぽいデバッグ表示(List編)

Last updated at Posted at 2013-02-13

List (Rubyでいう所のArray)

Rubyの場合

list.rb
list = [1, 2, 3]
puts list

C#の場合はLINQ , コレクション初期化子, String.Join を組み合わせると近い事が出来る。

List.cs
using System;
using System.Collections.Generic;
using System.Linq;

var list = new List<int>() { 1, 2, 3 };
Console.WriteLine("[" + String.Join(", ", from v in list select v) + "]");

出力はどちらも以下のようになる。

[1, 2, 3]

おまけ: Rubyでpinspectを使わずに自力で書く場合

C#が頑張ってる感じが伝わると思う。

jiriki.rb
puts "[" + list.map{|v| v}.join(", ") + "]"

静的言語でここまで出来るのは結構すごいなぁと思う。

C#でRubyっぽいデバッグ表示一覧

5
6
2

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
5
6