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

C#

 
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 
A quick and dirty solution;
C#
public class Rate
{
	public double Value; // Holds either the dollar or percentage value
	
	public override string ToString ()
	{
		string typeName = GetType().Name;
		// removes the prefix, if present
		if (typeName.StartsWith(typeof(Rate).Name))
			typeName = typeName.Substring(typeof(Rate).Name.Length);
		return typeName;
	}
}
// Console.WriteLine(myTransactionLine.Amount);
// would then result in "Dollar" as output

It'd be cleaner to introduce a new property than to abuse the ToString-method. Putting an enum in there that returns "Dollar" or "%" would require the base-class to have knowledge thereof.

..unless you introduce an abstract property that returns an object. Yes, that introduces an extra cast in the calling code, but that could easily be wrapped in a utility-method.
Bastard Programmer from Hell Suspicious | :suss:
if you can't read my code, try converting it here[^]

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 
GeneralMessage Removed Pin
27-Jul-12 13:52
professionalN_tro_P27-Jul-12 13:52 
GeneralRe: Track two types of values within one variable Pin
jschell28-Jul-12 6:33
jschell28-Jul-12 6:33 
AnswerRe: Track two types of values within one variable Pin
Trak4Net27-Jul-12 18:26
Trak4Net27-Jul-12 18:26 
GeneralRe: Track two types of values within one variable Pin
Paul Conrad28-Jul-12 9:32
professionalPaul Conrad28-Jul-12 9:32 
AnswerRe: Track two types of values within one variable Pin
Northcodedotno29-Jul-12 8:36
Northcodedotno29-Jul-12 8:36 
AnswerRe: Track two types of values within one variable Pin
BobJanova29-Jul-12 23:16
BobJanova29-Jul-12 23:16 
GeneralAdding databound ComboBox into cells of a DataGridView Pin
Dewald27-Jul-12 2:11
Dewald27-Jul-12 2:11 
QuestionHow to make GRIDVIEW as Rounded Corners Pin
mukusingh27-Jul-12 0:33
mukusingh27-Jul-12 0:33 
AnswerRe: How to make GRIDVIEW as Rounded Corners Pin
Richard MacCutchan27-Jul-12 1:57
mveRichard MacCutchan27-Jul-12 1:57 

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.