先看一段代码:C#中的ref参数问题

ClassA

{

public string name;

}

Class B : ClassA {}

public static void Main()

{

ClassB b = new ClassB();

b.name = "I'm class b";

//如果用Test(ref b)的话,编译会提示无法转换ClassB到ClassA

Console.WriteLine(Test(ref (ClassA)b));

}

public static string Test(ref ClassA class)

{

return class.name;

}

我的理解是这样强制转换应该没有什么问题的,但是上面的代码仍然无法通过编译,提示说参数必须为lvalue。郁闷... 哪位大虾遇到过同样的问题啊?

相关文章:

  • 2021-10-09
  • 2021-05-20
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
相关资源
相似解决方案