I am writing a new Betting BOT in C# for the new Betfair API and to solve some of the sins of the past BOT in which there were lots of loops and passing values to methods as parameters I am trying to split everything up as much as possible.
One method does one thing etc. I also want to define a Bet object that holds all my runner/race/bet info at the start of my "betting" job process and pass it into each method (PlaceBet, CancelBet, CheckBetStatus etc) where those values will be changed. I want to do this so at the end of the process I know all the values in my single Bet object are correct as at the moment I am using lots of variables which are getting mixed up along the way.
As I haven't done much work passing objects as reference in C# before I wanted to know the standard/best/official/fastest way of passing objects by reference.
Do I just do something like this
public struct Bet = {
public long BetID;
public double BetAmount;
public int MarketID;
public string BetStatus;
}
public BetfairBOT(){
Bet bet = new Bet;
// get info from DB
bet.BetID = 10002323;
bet.BetAmount = 10.00;
bet.MarketID=12342;
bet.BetStatus="";
// get current bet status;
this.GetBetStatus(ref bet);
// if not matched place bet
if(bet.BetStatus != "M"){
this.PlaceBet(ref bet);
}
// save to DB
this.SaveBet(ref bet);
}
private void GetBetStatus(ref Bet bet){
// do some stuff
bet.BetStatus = "U";
return;
}
or should I use the Bet object as the return type of the method and return it each time e.g
// get current bet status; Setting the bet object to the return object which is passed in by reference
bet = this.GetBetStatus(ref bet);
private Bet GetBetStatus(ref Bet bet){
// do some stuff
bet.BetStatus = "U";
// return my changed object
return bet;
}
Or should I do it some other way?
Also should I use the "out" parameter instead of "ref"?
I just want to know the "accepted" "best practise" way of passing objects in by reference and returning them so that I don't lose any data along the way.
By the way is there not a better way to format the code in this editor? I have tried indenting some of the ending brackets but they just don't want to be part of the code block above them.
Are there [code] tags I could use instead?
Thanks for any help in advance.
Rob