Better approach when obtaining multiple values from the same method at once

I have the following method which returns a tuple,

public Tuple<int, bool> GetStudentInformation(long stutID)

Called as,

Marks= GetStudentInformation((Id).Item1;
HasPassed= GetStudentInformation((Id).Item2;

This works fine as it is but I dont like that I call the same method twice to get item1 and item2, using Tuple is probably not the way ahead but any advice if c# has support to get two values returned over a single execution of the method?

>Solution :

You just need to save return value

Tuple<int, bool> info = GetStudentInformation(Id);

Marks = info.Item1;
HasPassed = info.Item2;

Leave a Reply