Skip to main content
deleted 21 characters in body
Source Link
Trae Moore
  • 187
  • 1
  • 8
if (characterInString >= '0' && char.IsDigit(characterInString <= '9')) { Frames.Throws.Add((int)char.GetNumericValue(characterInString));   var pinsCount = int.Parse(characterInString.ToString()); return pinsCount; } switch(char.ToUpperInvariant(characterInString)) { case 'X': Frames.IsStrike = true; Frames.IsFrameOver = true; Frames.Throws.Add(10); return 10; case '-': Frames.Throws.Add(0); return pinsCount;0; case '/': if(Frames.IsLastFrame && Frames.IsBonusAllowed) throw new ArgumentException("The Spare cannot be set on the Bonus Throws, please check."); Frames.IsSpare = true; Frames.IsFrameOver = true; Frames.Throws.Add(stratingPinsNumber - Frames.Throws[0]); return 10; default : throw new ArgumentException($"Invalid argument '{characterInString}' was detected in the provided input, please check."); } 
if (characterInString >= '0' && characterInString <= '9') { Frames.Throws.Add((int)char.GetNumericValue(characterInString)); pinsCount = int.Parse(characterInString.ToString()); return pinsCount; } switch(char.ToUpperInvariant(characterInString)) { case 'X': Frames.IsStrike = true; Frames.IsFrameOver = true; Frames.Throws.Add(10); return 10; case '-': Frames.Throws.Add(0); return pinsCount; case '/': if(Frames.IsLastFrame && Frames.IsBonusAllowed) throw new ArgumentException("The Spare cannot be set on the Bonus Throws, please check."); Frames.IsSpare = true; Frames.IsFrameOver = true; Frames.Throws.Add(stratingPinsNumber - Frames.Throws[0]); return 10; default : throw new ArgumentException($"Invalid argument '{characterInString}' was detected in the provided input, please check."); } 
if (char.IsDigit(characterInString)) { Frames.Throws.Add((int)char.GetNumericValue(characterInString));   var pinsCount = int.Parse(characterInString.ToString()); return pinsCount; } switch(char.ToUpperInvariant(characterInString)) { case 'X': Frames.IsStrike = true; Frames.IsFrameOver = true; Frames.Throws.Add(10); return 10; case '-': Frames.Throws.Add(0); return 0; case '/': if(Frames.IsLastFrame && Frames.IsBonusAllowed) throw new ArgumentException("The Spare cannot be set on the Bonus Throws, please check."); Frames.IsSpare = true; Frames.IsFrameOver = true; Frames.Throws.Add(stratingPinsNumber - Frames.Throws[0]); return 10; default : throw new ArgumentException($"Invalid argument '{characterInString}' was detected in the provided input, please check."); } 
added 1 character in body
Source Link
Trae Moore
  • 187
  • 1
  • 8
public static int ProcessCharArray(char characterInString, Frame Frames, int stratingPinsNumber) { int pinsCount = 0; if (characterInString >= '0' && char.IsDigit(characterInString <= '9')) { Frames.Throws.Add((int)char.GetNumericValue(characterInString)); pinsCount = int.Parse(characterInString.ToString()); } else if (char.ToUpperInvariant(characterInString) == 'X') { Frames.IsStrike = true; Frames.IsFrameOver = true; Frames.Throws.Add(10); pinsCount = 10; } else if (characterInString == '/') { Frames.IsSpare = true; Frames.IsFrameOver = true; Frames.Throws.Add(stratingPinsNumber - Frames.Throws[0]); pinsCount = 10; } else if (characterInString == '-') { Frames.Throws.Add(0); pinsCount += 0; } else if (characterInString == '/' && Frames.IsLastFrame && Frames.IsBonusAllowed) { throw new ArgumentException("The Spare cannot be set on the Bonus Throws, please check."); } else { throw new ArgumentException($"Invalid argument '{characterInString}' was detected in the provided input, please check."); } return pinsCount; } 

here is an alternative approach for the logic in your method as well. :)

if (characterInString >= '0' && characterInString <= '9') {  Frames.Throws.Add((int)char.GetNumericValue(characterInString)); pinsCount = int.Parse(characterInString.ToString()); return pinsCount; } switch(char.ToUpperInvariant(characterInString)) { case 'X': Frames.IsStrike = true; Frames.IsFrameOver = true; Frames.Throws.Add(10); return 10; case '-': Frames.Throws.Add(0); return pinsCount; case '/': if(Frames.IsLastFrame && Frames.IsBonusAllowed) throw new ArgumentException("The Spare cannot be set on the Bonus Throws, please check."); Frames.IsSpare = true; Frames.IsFrameOver = true; Frames.Throws.Add(stratingPinsNumber - Frames.Throws[0]); return 10; default : throw new ArgumentException($"Invalid argument '{characterInString}' was detected in the provided input, please check.");  } 
public static int ProcessCharArray(char characterInString, Frame Frames, int stratingPinsNumber) { int pinsCount = 0; if (characterInString >= '0' && characterInString <= '9') { Frames.Throws.Add((int)char.GetNumericValue(characterInString)); pinsCount = int.Parse(characterInString.ToString()); } else if (char.ToUpperInvariant(characterInString) == 'X') { Frames.IsStrike = true; Frames.IsFrameOver = true; Frames.Throws.Add(10); pinsCount = 10; } else if (characterInString == '/') { Frames.IsSpare = true; Frames.IsFrameOver = true; Frames.Throws.Add(stratingPinsNumber - Frames.Throws[0]); pinsCount = 10; } else if (characterInString == '-') { Frames.Throws.Add(0); pinsCount += 0; } else if (characterInString == '/' && Frames.IsLastFrame && Frames.IsBonusAllowed) { throw new ArgumentException("The Spare cannot be set on the Bonus Throws, please check."); } else { throw new ArgumentException($"Invalid argument '{characterInString}' was detected in the provided input, please check."); } return pinsCount; } 
public static int ProcessCharArray(char characterInString, Frame Frames, int stratingPinsNumber) { int pinsCount = 0; if (char.IsDigit(characterInString)) { Frames.Throws.Add((int)char.GetNumericValue(characterInString)); pinsCount = int.Parse(characterInString.ToString()); } else if (char.ToUpperInvariant(characterInString) == 'X') { Frames.IsStrike = true; Frames.IsFrameOver = true; Frames.Throws.Add(10); pinsCount = 10; } else if (characterInString == '/') { Frames.IsSpare = true; Frames.IsFrameOver = true; Frames.Throws.Add(stratingPinsNumber - Frames.Throws[0]); pinsCount = 10; } else if (characterInString == '-') { Frames.Throws.Add(0); pinsCount += 0; } else if (characterInString == '/' && Frames.IsLastFrame && Frames.IsBonusAllowed) { throw new ArgumentException("The Spare cannot be set on the Bonus Throws, please check."); } else { throw new ArgumentException($"Invalid argument '{characterInString}' was detected in the provided input, please check."); } return pinsCount; } 

here is an alternative approach for the logic in your method as well. :)

if (characterInString >= '0' && characterInString <= '9') {  Frames.Throws.Add((int)char.GetNumericValue(characterInString)); pinsCount = int.Parse(characterInString.ToString()); return pinsCount; } switch(char.ToUpperInvariant(characterInString)) { case 'X': Frames.IsStrike = true; Frames.IsFrameOver = true; Frames.Throws.Add(10); return 10; case '-': Frames.Throws.Add(0); return pinsCount; case '/': if(Frames.IsLastFrame && Frames.IsBonusAllowed) throw new ArgumentException("The Spare cannot be set on the Bonus Throws, please check."); Frames.IsSpare = true; Frames.IsFrameOver = true; Frames.Throws.Add(stratingPinsNumber - Frames.Throws[0]); return 10; default : throw new ArgumentException($"Invalid argument '{characterInString}' was detected in the provided input, please check.");  } 
added 1 character in body
Source Link
Trae Moore
  • 187
  • 1
  • 8

From a functional perspective, you could change your ProcessCharArray to stop allocating unneeded memory on the heap by using this. Being that a char is derivative of ValueType. The memory will be allocated on the stack within your defined scope and will keep the GC from cleaning up the mess that's created with characterInString.ToString().ToUpperInvariant() == "X"X".

public static int ProcessCharArray(char characterInString, Frame Frames, int stratingPinsNumber) { int pinsCount = 0; if (characterInString >= '0' && characterInString <= '9') { Frames.Throws.Add((int)char.GetNumericValue(characterInString)); pinsCount = int.Parse(characterInString.ToString()); } else if (char.ToUpperInvariant(characterInString) == 'X') { Frames.IsStrike = true; Frames.IsFrameOver = true; Frames.Throws.Add(10); pinsCount = 10; } else if (characterInString == '/') { Frames.IsSpare = true; Frames.IsFrameOver = true; Frames.Throws.Add(stratingPinsNumber - Frames.Throws[0]); pinsCount = 10; } else if (characterInString == '-') { Frames.Throws.Add(0); pinsCount += 0; } else if (characterInString == '/' && Frames.IsLastFrame && Frames.IsBonusAllowed) { throw new ArgumentException("The Spare cannot be set on the Bonus Throws, please check."); } else { throw new ArgumentException($"Invalid argument '{characterInString}' was detected in the provided input, please check."); } return pinsCount; } 

From a functional perspective, you could change your ProcessCharArray to stop allocating unneeded memory on the heap by using this. Being that a char is derivative of ValueType. The memory will be allocated on the stack within your defined scope and will keep the GC from cleaning up the mess that's created with characterInString.ToString().ToUpperInvariant() == "X.

public static int ProcessCharArray(char characterInString, Frame Frames, int stratingPinsNumber) { int pinsCount = 0; if (characterInString >= '0' && characterInString <= '9') { Frames.Throws.Add((int)char.GetNumericValue(characterInString)); pinsCount = int.Parse(characterInString.ToString()); } else if (char.ToUpperInvariant(characterInString) == 'X') { Frames.IsStrike = true; Frames.IsFrameOver = true; Frames.Throws.Add(10); pinsCount = 10; } else if (characterInString == '/') { Frames.IsSpare = true; Frames.IsFrameOver = true; Frames.Throws.Add(stratingPinsNumber - Frames.Throws[0]); pinsCount = 10; } else if (characterInString == '-') { Frames.Throws.Add(0); pinsCount += 0; } else if (characterInString == '/' && Frames.IsLastFrame && Frames.IsBonusAllowed) { throw new ArgumentException("The Spare cannot be set on the Bonus Throws, please check."); } else { throw new ArgumentException($"Invalid argument '{characterInString}' was detected in the provided input, please check."); } return pinsCount; } 

From a functional perspective, you could change your ProcessCharArray to stop allocating unneeded memory on the heap by using this. Being that a char is derivative of ValueType. The memory will be allocated on the stack within your defined scope and will keep the GC from cleaning up the mess that's created with characterInString.ToString().ToUpperInvariant() == "X".

public static int ProcessCharArray(char characterInString, Frame Frames, int stratingPinsNumber) { int pinsCount = 0; if (characterInString >= '0' && characterInString <= '9') { Frames.Throws.Add((int)char.GetNumericValue(characterInString)); pinsCount = int.Parse(characterInString.ToString()); } else if (char.ToUpperInvariant(characterInString) == 'X') { Frames.IsStrike = true; Frames.IsFrameOver = true; Frames.Throws.Add(10); pinsCount = 10; } else if (characterInString == '/') { Frames.IsSpare = true; Frames.IsFrameOver = true; Frames.Throws.Add(stratingPinsNumber - Frames.Throws[0]); pinsCount = 10; } else if (characterInString == '-') { Frames.Throws.Add(0); pinsCount += 0; } else if (characterInString == '/' && Frames.IsLastFrame && Frames.IsBonusAllowed) { throw new ArgumentException("The Spare cannot be set on the Bonus Throws, please check."); } else { throw new ArgumentException($"Invalid argument '{characterInString}' was detected in the provided input, please check."); } return pinsCount; } 
Source Link
Trae Moore
  • 187
  • 1
  • 8
Loading