I have a solution in which I instantiate a class with various types inside of it. I feel it is becoming to cumbersome to instantiate and then create variables for each of the types I want to access in the class (Option 2 in the code), so I've come up with a custom return type so I only have to return data once for use (option 1).
So with the struct my code is more readible in the MAIN block, but is there a better way to do this?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace retclass
{
class Program
{
static void Main(string[] args)
{
//Option 1 Struct and function
//create struct
ret x = new ret();
x = goofie(3, "this is the struct string");
Console.WriteLine("The String is {0}, the int is {1} and the value is {2}", x.str, x.num, x.yesno);
//Option 2 Class
//Instantiate retclass
retclass retins = new retclass();
retins.num = 3;
retins.str = "this is the class string";
if ((retins.num > 0) && retins.str != "")
{
retins.yesno = true;
}
Console.WriteLine("The String is {0}, the int is {1} and the value is {2}", retins.str, retins.num, retins.yesno);
Console.ReadLine();
}
public struct ret
{
public int num { get; set; }
public string str { get; set; }
public bool yesno { get; set; }
}
public static ret goofie(int isn, string ss)
{
ret dex = new ret();
dex.str = ss;
dex.num = isn;
if ((dex.str != "") && (dex.num > 0))
{
dex.yesno = true;
}
return dex;
}
}
public class retclass
{
public int num { get; set; }
public string str { get; set; }
public bool yesno { get; set; }
}
}