Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Xamarin应用程序在Device.OnPlatform和Switch()之间存在混淆_Android_Xamarin_Xamarin.forms - Fatal编程技术网

Android Xamarin应用程序在Device.OnPlatform和Switch()之间存在混淆

Android Xamarin应用程序在Device.OnPlatform和Switch()之间存在混淆,android,xamarin,xamarin.forms,Android,Xamarin,Xamarin.forms,我目前正在从事一个实习项目,要求我使用一个过时的项目。 我仍在尝试构建项目,消除了所有错误,但现在这些过时行的警告让我无法通过 我有以下错误: 警告CS0618“Device.OnPlatform(T,T,T)”已过时:“OnPlatform(通用)从2.3.4版起已过时。请改用switch(RuntimePlatform)。” 代码如下: using System; using System.Collections.Generic; using System.Linq; using Syste

我目前正在从事一个实习项目,要求我使用一个过时的项目。 我仍在尝试构建项目,消除了所有错误,但现在这些过时行的警告让我无法通过

我有以下错误:

警告CS0618“Device.OnPlatform(T,T,T)”已过时:“OnPlatform(通用)从2.3.4版起已过时。请改用switch(RuntimePlatform)。”

代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace MobileMedico.Classes
{
    public static class BoolResources
    {
        public static readonly bool ShouldShowBoxView =  Device.OnPlatform(true, false, true);
    }
}
遗憾的是,我不知道如何使用
开关
方法。有人能帮我吗?

是一个基本的C#关键字


是的,这种方法现在已经过时了。为了针对特定的设备,您必须使用switch语句,该语句将运行时平台作为参数

  static class AppConstants
{
    public static readonly Thickness PagePadding = GetPagePadding();

    private static Thickness GetPagePadding()
    {
        double topPadding;

        switch(Device.RuntimePlatform)
        {
            case Device.iOS:
                topPadding = 20;
                break;
            default:
                topPadding = 0;
                break;
        }

        return new Thickness(5, topPadding, 5, 0);
    }
}

这与java有关吗?如果没有,则删除java标记。@ADM确实没有。标记已删除。可能重复。这是否回答了您的问题?
  static class AppConstants
{
    public static readonly Thickness PagePadding = GetPagePadding();

    private static Thickness GetPagePadding()
    {
        double topPadding;

        switch(Device.RuntimePlatform)
        {
            case Device.iOS:
                topPadding = 20;
                break;
            default:
                topPadding = 0;
                break;
        }

        return new Thickness(5, topPadding, 5, 0);
    }
}