小编Ted*_*ddy的帖子

C#:将可空变量传递给只接受非空变量的方法

我有与此类似的代码:

public xyz (int? a)
{
  if (a.HasValue)
  { 
    // here DoSomething has parameters like DoSomething(int x)
    blah = DoSomething(a);
Run Code Online (Sandbox Code Playgroud)

我收到错误(无法从int?转换为int).有没有办法我可以将变量'a'传递给我的函数而不必这样做DoSomething(int? x)

c# nullable

6
推荐指数
2
解决办法
3329
查看次数

标签 统计

c# ×1

nullable ×1