主にC# な話題です
TryParse
の戻り値は null 許容型で良いんじゃないだろうか?
int i = int.TryParse("あ") ?? 0;
int? x = int.TryParse("あ");if (x == null) ・・・・
早速、拡張メソッドに加えてしまおう。
投稿日時 : 2008年3月7日 11:08
TryじゃなくてParseの戻り値でいいんじゃない?
僕は int x; if ( int.TryParse("あ",out x) ) { ... } の方がしっくりきますねぇ。 # 好みの問題でしかないんだけど。
επιστημηさん int x; if ( int.TryParse("あ",out x) ) { ... } ノ 禿同
int?.Parse の方がいいのでは? と思ったけど、そんなことできないのでは?
拡張メソッド
拡張メソッドはぁインスタンスからしか呼べませんw残念 (あ、また死語っぽいのつかってしまった・・)
シャノン さん >TryじゃなくてParseの戻り値でいいんじゃない? そうですね。 Try だと bool を返すのが自然という気がしますもんね。 ------------------------------------------------------- επιστημη さん、かずくん out で結果の値を取得することが、あまり好きではないんですよね。 ------------------------------------------------------- ghost_shell さん >と思ったけど、そんなことできないのでは? int.TryParse だと駄目ですね。 String の拡張メソッドになるかと思います。 こんな感じ? public static Int32? ToInt32(this string value) { Int32 r = 0; if (Int32.TryParse(value, out r)) return r; return null; } static void Main() { var q = new[] {"あ".ToInt32(), "12".ToInt32(), "-345".ToInt32() }; q.ToList().ForEach(x => Console.WriteLine(x)); } ------------------------------------------------------- myugaru さん >拡張メソッドはぁインスタンスからしか呼べませんw残念 ん?、上記のサンプルコードは動きますよ?
To 田中一郎Rせんせい >int.TryParse だと駄目ですね。 >String の拡張メソッドになるかと思います。 そうです。そういう意味です。 >ん?、上記のサンプルコードは動きますよ? "あ"はインスタンスだからっす。 ありがとうございましたm(_)m
すみません。名前のみすたいぴんぐいたしましたorz
ごめんなさい。 僕の元記事が端折りすぎでしたね。
http://www.eevance.com/tokei/chopard/index.html ロレックス買取"弊社はロレックスの商品特に大人気のロレックスデイトナシリーズのロレックス時計の種類を豊富に取り揃えます。日本ロレックス時計とロレックスレプリカのロレックスコピー品の品質よくて、激安税込み価格でご提供します。 }}}}}}
Link exchange is nothing else except it is simply placing the other person's website link on your page at appropriate place and other person will also do similar in support of you.
We are a group of volunteers and opening a new scheme in our community. Your web site provided us with useful information to work on. You've performed an impressive job and our entire community will be thankful to you.
It's amazing to pay a visit this site and reading the views of all mates about this post, while I am also keen of getting experience.
Powered by: Copyright © R・田中一郎