问题描述
在 short 中,是这样的:
private void checkMethod()
{
if (textBoxCode.Text.Contains("a").Position(Char.3)))
{
// Then do this...
}
}
解决方法
如果我完全理解您的伪代码。有很多方法,但是我想您可以做类似的事情
if(textBoxCode.Text?.Length >= 3 && textBoxCode.Text[2] == 'a')
呼叫textBoxCode.Text?.Length
是基本的容错能力
或者您可以使用ElementAtOrDefault
来完成以上所有操作
以序列或默认值的指定索引返回元素 索引超出范围时的值。
if(textBoxCode.Text?.ElementAtOrDefault(2) == 'a')
,
调用Substring获取特定字符。
if(case == SampleCase.STR) {
obj1.call();
} else if(case == SampleCase.I) {
obj2.call();
} else if(....)
...