locked
Different behavior while creating ValueTuple RRS feed

  • Question

  • ValueTuple as a new feature in C# 7.0 is having public method Create which helps to create ValueTuples (from <c>singleton to octuple</c> or more) on the other hand we can also use new to achieve the same results. I noticed these behave differently. I am trying to research is below implementation wrong or this is something as per design:

    Method CreateOctuple() is working as expected:

       

    private static ValueTuple<int, int, int, int, int, int, int, ValueTuple<int>> CreateOctuple()
        {
             return new ValueTuple<int, int, int, int, int, int, int, ValueTuple<int>>(1, 2, 3, 4, 5, 6, 7, new ValueTuple<int>(8)); ;
        }

    Now, I tried to achieve same output using ```Create()``` method, unfortunately, it is complaining about the return type:

       

    private static ValueTuple<int, int, int, int, int, int, int, ValueTuple<int>> OctupleUsingCreate()
        {
            return ValueTuple.Create(1, 2, 3, 4, 5, 6, 7, ValueTuple.Create(8));
        }

    What is wrong here?



    Thanks & Regards,
    Gaurav Arora


    • Edited by Gaurav Aroraa Tuesday, May 23, 2017 9:07 AM added snapshot
    Sunday, May 21, 2017 8:00 AM

Answers

  • Finally, got to know the solution:

    private static ValueTuple<int, int, int, int, int, int, int, int> CreateOctuple()
    
    {
             return new ValueTuple<int, int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7, 8);
    }

    private static ValueTuple<int, int, int, int, int, int, int, int> OctupleUsingCreate()
    {
            return ValueTuple.Create(1, 2, 3, 4, 5, 6, 7, 8);
    }

    Above code(s) works fine, the return type errors are just due to Resharper. Code is working and giving output as expected. So, the issue is related to Resharper not C# 7.0 - ValueTuple.


    Tuesday, May 23, 2017 9:15 AM

All replies

  • Have you tried ‘return ValueTuple.Create(1, 2, 3, 4, 5, 6, 7, 8)’?

    Sunday, May 21, 2017 8:14 AM
  • Finally, got to know the solution:

    private static ValueTuple<int, int, int, int, int, int, int, int> CreateOctuple()
    
    {
             return new ValueTuple<int, int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7, 8);
    }

    private static ValueTuple<int, int, int, int, int, int, int, int> OctupleUsingCreate()
    {
            return ValueTuple.Create(1, 2, 3, 4, 5, 6, 7, 8);
    }

    Above code(s) works fine, the return type errors are just due to Resharper. Code is working and giving output as expected. So, the issue is related to Resharper not C# 7.0 - ValueTuple.


    Tuesday, May 23, 2017 9:15 AM
  • This is what the main issue. Found solution and posted in the thread.

    Thanks &amp;amp; Regards, Gaurav Kumar Arora http://gaurav-arora.com http://mynangal.com

    Monday, July 3, 2017 7:58 PM