Click here to Skip to main content
15,887,350 members
Home / Discussions / C#
   

C#

 
Questionhow to set label text here? Pin
Jassim Rahma27-Jul-12 7:36
Jassim Rahma27-Jul-12 7:36 
AnswerRe: how to set label text here? Pin
Ravi Bhavnani27-Jul-12 8:09
professionalRavi Bhavnani27-Jul-12 8:09 
GeneralRe: how to set label text here? Pin
Jassim Rahma27-Jul-12 9:25
Jassim Rahma27-Jul-12 9:25 
AnswerRe: how to set label text here? Pin
Ravi Bhavnani27-Jul-12 9:40
professionalRavi Bhavnani27-Jul-12 9:40 
AnswerRe: how to set label text here? Pin
OriginalGriff27-Jul-12 9:16
mveOriginalGriff27-Jul-12 9:16 
GeneralRe: how to set label text here? Pin
Ravi Bhavnani27-Jul-12 9:41
professionalRavi Bhavnani27-Jul-12 9:41 
GeneralRe: how to set label text here? Pin
OriginalGriff27-Jul-12 9:47
mveOriginalGriff27-Jul-12 9:47 
QuestionTrack two types of values within one variable Pin
hpjchobbes27-Jul-12 4:55
hpjchobbes27-Jul-12 4:55 
I'm still new, so I don't know if this is the best way to do what I am needing, and would like some feedback/advice.

I have a class that contains a double value. This double could represent a dollar value or it could represent a percentage value. Only one or the other, it will never have both. At runtime, I will need to be able to tell what type of value this is. Here is what I came up with, which appears to work, but if there is a better way, I would prefer that.
C#
public class Rate
{
     public double Value; // Holds either the dollar or percentage value
}
public class RateDollar : Rate {}
public class RatePercentage : Rate {}

public class TransactionLine
{
   // There's more stuff here, but it's not relevant to show
   public Rate Amount;
}


// Set the rate amount to be a dollar 
myTransactionLine.Amount = new RateDollar();

// I can check the type if needed
if(myTransactionLine.Amount.GetType() == typeof(RateDollar)) // We have a dollar value
if(myTransactionLine.Amount.GetType() == typeof(RatePercent)) // We have a percentage value


For some reason, this seems like it is a clunky workaround. It also seems like it's possible for someone to create the value that is neither a RateDollar or RatePercent, and just as a plain Rate. Is there some way to prevent this, or is there a better way to accomplish what I am trying to do?
AnswerRe: Track two types of values within one variable Pin
SledgeHammer0127-Jul-12 6:28
SledgeHammer0127-Jul-12 6:28 
GeneralRe: Track two types of values within one variable Pin
hpjchobbes27-Jul-12 7:04
hpjchobbes27-Jul-12 7:04 
GeneralMessage Removed Pin
27-Jul-12 6:38
professionalN_tro_P27-Jul-12 6:38 
GeneralRe: Track two types of values within one variable Pin
hpjchobbes27-Jul-12 7:18
hpjchobbes27-Jul-12 7:18 
GeneralRe: Track two types of values within one variable Pin
BillWoodruff29-Jul-12 18:35
professionalBillWoodruff29-Jul-12 18:35 
GeneralRe: Track two types of values within one variable Pin
SledgeHammer0127-Jul-12 11:40
SledgeHammer0127-Jul-12 11:40 
GeneralMessage Removed Pin
27-Jul-12 12:22
professionalN_tro_P27-Jul-12 12:22 
GeneralRe: Track two types of values within one variable Pin
SledgeHammer0127-Jul-12 12:33
SledgeHammer0127-Jul-12 12:33 
AnswerRe: Track two types of values within one variable Pin
Eddy Vluggen27-Jul-12 7:13
professionalEddy Vluggen27-Jul-12 7:13 
GeneralRe: Track two types of values within one variable Pin
hpjchobbes27-Jul-12 7:23
hpjchobbes27-Jul-12 7:23 
GeneralRe: Track two types of values within one variable Pin
Eddy Vluggen27-Jul-12 8:24
professionalEddy Vluggen27-Jul-12 8:24 
GeneralRe: Track two types of values within one variable Pin
PIEBALDconsult27-Jul-12 8:15
mvePIEBALDconsult27-Jul-12 8:15 
AnswerRe: Track two types of values within one variable Pin
SledgeHammer0127-Jul-12 11:45
SledgeHammer0127-Jul-12 11:45 
GeneralRe: Track two types of values within one variable Pin
jschell27-Jul-12 11:57
jschell27-Jul-12 11:57 
GeneralRe: Track two types of values within one variable Pin
Paul Conrad28-Jul-12 9:31
professionalPaul Conrad28-Jul-12 9:31 
GeneralMessage Removed Pin
27-Jul-12 12:24
professionalN_tro_P27-Jul-12 12:24 
GeneralRe: Track two types of values within one variable Pin
SledgeHammer0127-Jul-12 12:36
SledgeHammer0127-Jul-12 12:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.