Deepak
Deepak

Reputation: 739

Tuples in C# 4.0 - passing class objects

I have a function that returns a tuple made up of two objects of the same class.

class MyClass
{
     public int i;
     public char c;
};

Now, I have a function that returns IEnumerable

public IEnumerable<Tuple<MyClass, MyClass>> Func1()
{
.....
.....

yield return Tuple.Create(MyClassObj1, MyClassObj2);
}

And I have one more function that access this tuple as a parameter.

public void Func2(Tuple<MyClass, MyClass> Pair)
{
   //here I can access Pair.Item1 and Pair.Item2 but not Pair.Item1.i or Pair.Item2.c    
}

Now, how do I access the member elements of the objects MyClassObj1 and MyClassObj2 inside Func2?

Upvotes: 0

Views: 783

Answers (1)

Tim Robinson
Tim Robinson

Reputation: 54764

how do i access the member elements of the objects MyClassObj1 and MyClassObj2 inside Func2?

Make them public in the declaration of MyClass. The compiler error message should give some clues.

Upvotes: 4

Related Questions