Click here to Skip to main content
15,888,233 members
Home / Discussions / C#
   

C#

 
Questioncan't get float value Pin
zhiyuan1630-Aug-10 22:22
zhiyuan1630-Aug-10 22:22 
AnswerRe: can't get float value Pin
Bigdeak30-Aug-10 23:00
Bigdeak30-Aug-10 23:00 
AnswerRe: can't get float value Pin
phil.o31-Aug-10 0:34
professionalphil.o31-Aug-10 0:34 
AnswerRe: can't get float value Pin
Luc Pattyn31-Aug-10 2:23
sitebuilderLuc Pattyn31-Aug-10 2:23 
QuestionAbstract Static and Inheritance Pin
Matthew Klein30-Aug-10 15:28
Matthew Klein30-Aug-10 15:28 
AnswerRe: Abstract Static and Inheritance Pin
PIEBALDconsult30-Aug-10 16:50
mvePIEBALDconsult30-Aug-10 16:50 
GeneralRe: Abstract Static and Inheritance Pin
Matthew Klein31-Aug-10 4:38
Matthew Klein31-Aug-10 4:38 
GeneralRe: Abstract Static and Inheritance Pin
Chris Trelawny-Ross31-Aug-10 5:35
Chris Trelawny-Ross31-Aug-10 5:35 
I wonder if having Car, Van, Truck (etc.?) as distinct C# types is the root of the problem.

What would be the pros & cons of having a simple Vehicle class (and, probably, you would no longer need an ItemBase class)?

Here's how I might implement Vehicle:
public enum VehicleType { Car, Van, Truck }
 

class Vehicle
	{
	public VehicleType VehicleType { get; set; }
 
	static private readonly Dictionary<VehicleType, List<string>> _availableUpgrades = new Dictionary<VehicleType, List<string>>();
 
	public static List<string> GetAvailableUpgrades(VehicleType vehicleType)
		{
		if (!_availableUpgrades.ContainsKey(vehicleType))
			throw new ArgumentException("Vehicle type " + vehicleType + " not recognized in upgrades collection.");
		return _availableUpgrades[vehicleType];
		}
	// ...
	}


If you absolutely must have distinct classes for each vehicle type, perhaps this would work:

	class  ItemBase
		{
		static private readonly Dictionary<Type, List<string>> _availableUpgrades = new Dictionary<Type, List<string>>();
 
		public List<string> GetAvailableUpgrades()
			{
			Type myType = GetType();
			if (!_availableUpgrades.ContainsKey(myType))
				throw new ArgumentException("Vehicle type " + myType.Name + " not recognized in upgrades collection.");
			return _availableUpgrades[myType];
			}
		}
 
	class Car : ItemBase
		{
		// ...
		}

AnswerRe: Abstract Static and Inheritance Pin
Ennis Ray Lynch, Jr.31-Aug-10 6:16
Ennis Ray Lynch, Jr.31-Aug-10 6:16 
QuestionC# - Easy - Music Player & Next Song [modified] Pin
Martiinus30-Aug-10 13:52
Martiinus30-Aug-10 13:52 
AnswerRe: C# - Easy - Music Player & Next Song Pin
Luc Pattyn30-Aug-10 15:00
sitebuilderLuc Pattyn30-Aug-10 15:00 
AnswerRe: C# - Easy - Music Player & Next Song Pin
Martiinus30-Aug-10 15:27
Martiinus30-Aug-10 15:27 
AnswerRe: C# - Easy - Music Player & Next Song Pin
Luc Pattyn30-Aug-10 15:48
sitebuilderLuc Pattyn30-Aug-10 15:48 
QuestionPassing a C# variable to included javascript file Pin
Sonar8730-Aug-10 12:41
Sonar8730-Aug-10 12:41 
AnswerRe: Passing a C# variable to included javascript file Pin
Not Active30-Aug-10 15:22
mentorNot Active30-Aug-10 15:22 
GeneralRe: Passing a C# variable to included javascript file Pin
Sonar8730-Aug-10 15:55
Sonar8730-Aug-10 15:55 
GeneralRe: Passing a C# variable to included javascript file Pin
Not Active30-Aug-10 16:07
mentorNot Active30-Aug-10 16:07 
GeneralRe: Passing a C# variable to included javascript file Pin
Sonar8730-Aug-10 17:12
Sonar8730-Aug-10 17:12 
GeneralRe: Passing a C# variable to included javascript file Pin
Not Active31-Aug-10 0:26
mentorNot Active31-Aug-10 0:26 
GeneralRe: Passing a C# variable to included javascript file Pin
Sonar8731-Aug-10 9:39
Sonar8731-Aug-10 9:39 
QuestionParsing a string Pin
jenya730-Aug-10 4:16
jenya730-Aug-10 4:16 
AnswerRe: Parsing a string Pin
Ennis Ray Lynch, Jr.30-Aug-10 4:18
Ennis Ray Lynch, Jr.30-Aug-10 4:18 
GeneralRe: Parsing a string Pin
jenya730-Aug-10 4:23
jenya730-Aug-10 4:23 
GeneralRe: Parsing a string Pin
Ennis Ray Lynch, Jr.30-Aug-10 4:25
Ennis Ray Lynch, Jr.30-Aug-10 4:25 
GeneralRe: Parsing a string Pin
jenya730-Aug-10 4:26
jenya730-Aug-10 4:26 

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.