gpt4 book ai didi

c# - 在 C# 中创建自定义常量后缀

转载 作者:行者123 更新时间:2023-11-30 13:13:24 25 4
gpt4 key购买 nike

我正在尝试为无限大小的整数值开发一个类,我需要的只是制作一个与赋值运算符一起使用的新自定义常量后缀。

例如:

假设类名是 BigInt,创建的 Suffix 是 B

赋值语句是这样的

// B character will tell the compiler about the New Data Type
BigInt x = 111111111111111111111111111111111111111111111111B;

有什么办法可以实现吗?

特别问候

最佳答案

没有。语言/编译器不支持这个。您可能想要研究的接近的东西是隐式的 conversion operator .那会让你做这样的事情:

BigInt b = "1234";

public class BigInt
{
public static implicit operator BigInt(string value)
{
return new BigInt {Value = value};
}
public string Value { get; private set; }
}

关于c# - 在 C# 中创建自定义常量后缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11268213/

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