Challenge Tuples

matheus matheus at gmail.com
Fri Apr 26 15:34:51 UTC 2024


On Friday, 26 April 2024 at 13:25:34 UTC, Salih Dincer wrote:
> ...

Very nice, for your first example I need to think a bit because 
I'm bit rusty in C#, but I think it will not be as easier as D 
version.

For the bonus part:

private static void Main(string[] args){
     var a = (1,2,3,(1,3),5);
     var t = a as ITuple;
     var xx = new List<string>();

     for(var i=0;i<t.Length;++i){
        if(t[i].GetType() == 
typeof(System.ValueTuple<Int32,Int32>)){
           var t2 = (t[i] as ITuple);
           var s = 0;
           for(var j=0;j<t2.Length;++j){
               s+=(int)t2[j];
           }
           xx.Add(s.ToString());
        }else{
           xx.Add(t[i].ToString());
        }
     }

     Console.WriteLine(string.Join(",",xx));
     return;
}

Again I'm rusty in C#... but so far yes it's more verbose than 
the D version.

Matheus.


More information about the Digitalmars-d-learn mailing list