[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
<?xml version="1.0" encoding="utf-8" ?><configuration><startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0"/></startup></configuration>
5.times { |i| puts i }Rubyを使ったことのない方のために言うと、
0 1 2 3 4
class Program { static void Main(string[] args) { for (int i = 0; i < 5; i++) { System.Console.WriteLine(i); } } }
static class Int32Extension { public static void Times(this int loopCount, System.Action<int> loop) { for (int i = 0; i < loopCount; i++) { loop(i); } } }
class Program { static void Main(string[] args) { 5.Times(i => System.Console.WriteLine(i)); } }
using System; class Person { public int Age { get; set; } } static class PersonExtension { public static bool IsAdult(this Person person) { return person.Age >= 20; } } class Program { static void Main(string[] args) { Person child = new Person { Age = 10 }; Person father = new Person { Age = 35 }; Console.WriteLine(child.IsAdult()); //False Console.WriteLine(father.IsAdult()); //True } }
using System; using System.IO; interface IPerson { int Age { get; set; } } class Person : IPerson { public int Age { get; set; } } class PersonFile : IPerson { public int Age { get { return Int32.Parse(File.ReadAllText("person.txt")); } set { File.WriteAllText("person.txt", value.ToString()); } } } static class PersonExtension { public static bool IsAdult(this IPerson person) { return person.Age >= 20; } } class Program { static void Main(string[] args) { Person child = new Person { Age = 10 }; PersonFile father = new PersonFile { Age = 35 }; Console.WriteLine(child.IsAdult()); Console.WriteLine(father.IsAdult()); } }とりあえずPersonクラスに似た、PersonFileクラスを作りました。