gpt4 book ai didi

c# - 范围内的局部或参数错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:51:12 25 4
gpt4 key购买 nike

我正在努力理解和修复我在尝试从文本中获取数字时遇到的错误。

实际上我有两段来自 alternativeAirportPrice.Text 的文本。一个说:

+156 on same day

所以我只想从这段文本中输出 156另一个说:

-156 on same day

所以我只想输出 - 156 来自这个文本

我实现了 foreach 方法以使用 char.IsNumber(),但是我在 中收到了 c 的错误选择(c => c.toString())

错误是:

a local or parameter name 'c' cannot be declared in this scope because that name is TestSuite used in an enclosing local scope to define a local or parameter.

我需要做什么来解决这个问题并能够从文本中吐出数字?

public string GetAlternativeAirportPrice(By airportPriceLocator)
{
var alternativeAirportPrices = _driver.FindElements(airportPriceLocator);

foreach (var alternativeAirportPrice in alternativeAirportPrices)
{
if (alternativeAirportPrice.Displayed)
foreach (char c in alternativeAirportPrice.Text)
{
if (char.IsNumber(c))
{
alternativeAirportPrice.Text.ToCharArray().Select(c => c.ToString()).ToArray();
}
}
return alternativeAirportPrice.Text;
}
return null;
}

最佳答案

这是因为您已经在以下行的代码中声明了 c:

foreach (char c in alternativeAirportPrice.Text)

因此您不能在您的Select 中再次使用它。尝试使用其他东西代替,例如 x:

.Select(x => x.ToString())

或者尝试将 c 重命名为 foreach 中的其他名称,例如 item:

foreach (char item in alternativeAirportPrice.Text)
{
if (char.IsNumber(item))

关于c# - 范围内的局部或参数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47235503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com