在 C# 中,我这样做:
public const double PAPER_SIZE_WIDTH = 8.5 * 96;
Run Code Online (Sandbox Code Playgroud)
在 F# 中定义此全局常量的最佳方法是什么?
这失败了:
[<Literal>]
let PaperSizeWidth = 8.5*96.0
Run Code Online (Sandbox Code Playgroud)
错误:这不是有效的常量表达式
TIA
我试图在我的Test.cs中访问我的其他类TerminalStrings.cs中的字符串,但是无法...我怎样才能访问它们?
TerminalStrings.cs:
namespace RFID_App
{
class TerminalStrings
{
public static readonly string identiError = "ERROR";
public const string identiSuccess = "SUCCESS";
}
}
Run Code Online (Sandbox Code Playgroud)
在Test.cs中:
namespace RFID_App
{
class Test
{
public Test()
{
string test;
TerminalStrings stringlist = new TerminalStrings();
test = stringlist.identiError; //this was not possible
}
}
}
Run Code Online (Sandbox Code Playgroud) 这是我的课:
namespace My.Core
{
public static class Constants
{
public const string Layer_ver_const = "23";
public const string apiHash_const = "111111";
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想为apiHash_const设置条件值。
意思 :
if(Layer_ver_const == "23")
{
apiHash_const = "111111";
}
else if(Layer_ver_const == "50")
{
apiHash_const = "222222";
}
else
{
apiHash_const = "333333";
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一个配置类商店应用程序配置.目前我正在使用静态类.一些配置与一个主题相关,所以我想将它们组织成一个嵌套类,所以我可以引用这样的配置:
AppConfig.Url
AppConfig.LogSettings.FileSize
Run Code Online (Sandbox Code Playgroud)
我有两个选项,要么使用静态嵌套类,
public static class AppConfig
{
public static class LogSettings
{
public static int FileSize {get; set;}
}
}
Run Code Online (Sandbox Code Playgroud)
或声明一个类但添加一个静态属性:
public static class AppConfig
{
public class LogSettings
{
public int FileSize {get; set;}
}
public static LogSettings logSettings { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)
但是,它们都不能保护被其他类修改的嵌套类成员FileSize,即使我private set用来保护公共静态属性.也许我不应该使用嵌套类来实现它?有什么建议?