gpt4 book ai didi

c# - 警告 CS0114 : `AnApp.AppDelegate.Self' hides inherited member

转载 作者:行者123 更新时间:2023-11-29 02:22:52 30 4
gpt4 key购买 nike

今天我更新到 Xamarin.iOS 8.6.0.51。现在我收到以下警告:

Warning CS0114: AnApp.AppDelegate.Self' hides inherited member
MonoTouch.Foundation.NSObject.Self'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword (CS0114)

在我的 AppDelegate.cs 中,我定义了以下属性/字段:

public static AppDelegate Self { get; private set; }

比起我以这种方式设置它以获得对应用程序委托(delegate)的引用(就像在 this thread 中提出的那样):

AppDelegate.Self = this;

这在更新之前有效。我用它来实例化 Storyboard中的一些 View Controller 和其他一些东西(网络事件指示器,......)。我必须改变什么才能让它工作?我不再需要这个了,还是应该重命名 Self

最佳答案

这意味着 AppDelegate 的基类也有名为 Self 的成员,编译器会警告您您可能在不知不觉中隐藏了基类成员。

如果您知道自己在做什么,那么您可以使用 new 关键字安全地抑制警告。

public static new AppDelegate Self { get; private set; }

这绝对没有任何区别,没有 new 关键字,您的应用程序也可以正常工作。它只是告诉 c# 编译器我有意为成员使用相同的名称,并且我有兴趣隐藏基类成员。

关于c# - 警告 CS0114 : `AnApp.AppDelegate.Self' hides inherited member,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27921239/

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