我是一名 C++ 开发人员,最近转向 C#。我正在开发一个 WPF 应用程序,我需要在其中检查 CASE Sensitive。我在 C++ 中完成了如下操作:
// BoardName and Board Version are of tye String
if(m_boardName->compareIgnoreCase("S1010012") == 0)
{
m_voltageChannels = redhookChannels;
}
else if(m_boardName->compareIgnoreCase("S1010018") == 0)//For bavaria board
{
if(m_boardVersion->compareIgnoreCase("001A") == 0 ||
m_boardVersion->compareIgnoreCase("001B") == 0 ||
m_boardVersion->compareIgnoreCase("001C") == 0 )
{
m_voltageChannels = bavaria1Channels;
}
else if(m_boardVersion->compareIgnoreCase("002B") == 0)
{
m_voltageChannels = bavaria2Channel;
}
}
在我的 WPF 应用程序中,我这样做了:
string redhookboardname = "S1010012";
string redhookboardnameCase = "s1010012";
string bavariaboardnameCase = "s1010018";
string bavaria1boardversion1Case = "001a";
string bavaria1boardversion2Case = "001b";
string bavaria1boardversion3Case = "001c";
string bavariaboardname = "S1010018";
string bavaria1boardversion1 = "001A";
string bavaria1boardversion2 = "001B";
string bavaria1boardversion3 = "001C";
string bavaria2boardversion = "002B";
string bavaria2boardversionCase = "002b";
public void OnChannel()
{
if (redhookboardnameCase.Equals(redhookboardname, StringComparison.InvariantCultureIgnoreCase))
{
mVoltageStruct = redhookboard;
}
else if (bavariaboardnameCase.Equals(bavaria1boardversion1, StringComparison.InvariantCultureIgnoreCase))
{
if (bavaria1boardversion1Case.Equals(bavariaboardname, StringComparison.InvariantCultureIgnoreCase)
|| bavaria1boardversion2Case.Equals(bavaria1boardversion2, StringComparison.InvariantCultureIgnoreCase)
|| bavaria1boardversion3Case.Equals(bavaria1boardversion3, StringComparison.InvariantCultureIgnoreCase))
{
mVoltageStruct = bavaria1board;
}
else if (bavaria2boardversionCase.Equals(bavaria2boardversion, StringComparison.InvariantCultureIgnoreCase))
{
mVoltageStruct = bavaria2board;
}
}
}
[更新代码]:这可以像我上面那样实现吗???