Skip to content

Instantly share code, notes, and snippets.

@deepumi
Last active March 26, 2017 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepumi/b72a85c135a51ee86590fd7ac32efc4a to your computer and use it in GitHub Desktop.
Save deepumi/b72a85c135a51ee86590fd7ac32efc4a to your computer and use it in GitHub Desktop.
PropertyBag class for return multiple values
public struct PropertyBag<T1, T2>
{
public PropertyBag(T1 t1, T2 t2)
{
Item1 = t1;
Item2 = t2;
}
public T1 Item1;
public T2 Item2;
}
public struct PropertyBag<T1, T2, T3>
{
public PropertyBag(T1 t1, T2 t2, T3 t3)
{
Item1 = t1;
Item2 = t2;
Item3 = t3;
}
public T1 Item1;
public T2 Item2;
public T3 Item3;
}
public struct PropertyBag
{
public static PropertyBag<T1, T2> Create<T1, T2>(T1 t1, T2 t2)
{
return new PropertyBag<T1, T2>(t1, t2);
}
public static PropertyBag<T1, T2, T3> Create<T1, T2, T3>(T1 t1, T2 t2, T3 t3)
{
return new PropertyBag<T1, T2, T3>(t1,t2,t3);
}
}
//Usage
void Main()
{
var result = SomeMethod();
Console.WriteLine(result.Item1);
Console.WriteLine(result.Item1);
Console.WriteLine(result.Item3);
}
public PropertyBag<int, string, double> SomeMethod()
{
return PropertyBag.Create(2, "Test",3.5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment