Hi! I made a code that asks the user to enter the name of the month and prints whether the month has 30 days. I made it with if/else, but now I want to make the same one but with SWITCH. The switches are new to me so I would be very grateful if someone can help me. Much...
在试着用多态,子类来解决if/else 的问题时,resharper的convert if to switch太好用了。
Control Generation of Switch-Case Statements for If-ElseIf-Else Patterns Recommended Settings ApplicationSetting DebuggingNo impact TraceabilityOff EfficiencyOn (execution, ROM), No impact (RAM) Safety precautionNo impact Programmatic Use Parameter:ConvertIfToSwitch ...
= null) formatter = provider.GetFormat(typeof(TemperatureProvider)) as TemperatureProvider; if (String.IsNullOrWhiteSpace(fmt)) { if (formatter != null) fmt = formatter.Format; else fmt = "G"; } switch (fmt.ToUpper()) { case "G": case "C": return m_Temp.ToString("N2") + "°C"...
= null) formatter = provider.GetFormat(typeof(TemperatureProvider)) as TemperatureProvider; if (String.IsNullOrWhiteSpace(fmt)) { if (formatter != null) fmt = formatter.Format; else fmt = "G"; } switch (fmt.ToUpper()) { case "G": case "C": return m_Temp.ToString("N2") + "°C"...
= null) fmt = formatter.Format; else fmt = "G"; } switch (fmt.ToUpper()) { case "G": case "C": return m_Temp.ToString("N2") + "°C"; case "F": return Fahrenheit.ToString("N2") + "°F"; case "K": return Kelvin.ToString("N2") + " K"; default: throw new Format...
public object GetFormat( Type argType ) { if ( argType == typeof( AverageInfo ) ) return this; else return null; } // Use this property to set or get the type of averaging. public AverageType TypeOfAverage { get { return this.AvgType; } set { this.AvgType = value; } } } ...
public object GetFormat( Type argType ) { if ( argType == typeof( AverageInfo ) ) return this; else return null; } // Use this property to set or get the type of averaging. public AverageType TypeOfAverage { get { return this.AvgType; } set { this.AvgType = value; } } } ...
public object GetFormat( Type argType ) { if ( argType == typeof( AverageInfo ) ) return this; else return null; } // Use this property to set or get the type of averaging. public AverageType TypeOfAverage { get { return this.AvgType; } set { this.AvgType = value; } } } ...
sbyte sourceNumber = SByte.MinValue; bool isSigned = Math.Sign((sbyte)sourceNumber.GetType().GetField("MinValue").GetValue(null)) == -1; string value = sourceNumber.ToString("X"); byte targetNumber; try { targetNumber = Convert.ToByte(value, 16); if (isSigned && ((targetNumber &...