Xamarin.android 可以在项目中添加静态类

Xamarin.android 可以在项目中添加静态类,xamarin.android,Xamarin.android,对于我的Xamarin Android项目,我有以下问题: 1) 可以在项目中添加静态类吗?下面的类用于WinRT项目 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MobileSales.DataModel { static class TransItemSelected {

对于我的Xamarin Android项目,我有以下问题:

1) 可以在项目中添加静态类吗?下面的类用于WinRT项目

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MobileSales.DataModel { static class TransItemSelected { public static int DocType { get; set; } public static string DocNo { get; set; } public static int TransId { get; set; } .... } } 使用制度; 使用System.Collections.Generic; 使用System.Linq; 使用系统文本; 使用System.Threading.Tasks; 命名空间MobileSales.DataModel { 选择静态类transitem { 公共静态int DocType{get;set;} 公共静态字符串DocNo{get;set;} 公共静态int TransId{get;set;} .... } } 2) 如何在Activity.cs中获取和设置上述类的数据

3) 如何设置要在Android平板电脑中使用的项目

谢谢

1)是的(但在许多情况下不推荐)

2) TransItemSelected.DocType=0

3) 在Android项目中包括该文件(类库或应用程序)

不过,一定要把这门课公之于众

public static class TransItemSelected
{
     ....

我可以问一下为什么不能使用静态类吗?可以,没有任何东西阻止它的使用。如果你的类不维护状态,那么它可以是静态的。不过,如果静态类需要维护状态,那么使用常规实例类并不是一种好的做法。