我可以像这样用typescript来做:
let greet: 'Hey' | 'Hi' | 'Hello';
// Now greet will allow only above specified string values
greet = 'Hi'; // no Type Error here
greet = 'Welcome'; // throws a Type Error
如何在Dart中实现等效项?
我有以下代码,我想知道是否有一种方法可以使用switch块而不是一堆if/else语句。我知道Java在Java 1.7中支持转换块中的字符串,但我仍然在使用Java 1.6:
} else if (typeName.equals("Boolean")) {
return new SwitchInputType<Boolean>(new Boolean((String) memberValue));
} else if (typeName.equals("Double")) {
r
在下面的@RelationshipEntity中,您可以看到我有一个Set<Right> rights (一组权限)。Right是一个Emum。Neo4J只允许我保存一组String,所以我创建了一个自定义的转换器。
@RelationshipEntity (type="LOGIN")
public class Login {
@GraphId
Long id;
@StartNode
Person person;
@EndNode
Organisation organisation;
@Property
我正在尝试使用Enum值作为对象的键,希望它在得到值时保留类型,但我得到的是Element implicitly has an 'any' type because expression of type 'string' can't be used to index type。
export enum TaskType {
Classification = 'classification',
Extraction = 'extraction'
}
const comparisons: { [name in Task
有没有办法在C#中实现反向枚举或常量文件?我有一个列表中的ID,并希望将一个常量字符串映射到这个ID。
常规enum
public enum StaticUser
{
DB = 1,
Order = 2
}
我需要的是:
public enum StaticUser
{
1 = DB,
2 = Order
}
例如:
public enum Day {
MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY,SUNDAY;
}
给定枚举MONDAY、WEDNESDAY、SATURDAY,我可以得到元素为["monday", "wednesday", "saturday"]的列表或集合。Java中有什么方法吗?或者其他的Util类?
如何在TypeScript中使用泛型将字符串转换为枚举?
export function getMethodEnum<T>(actionStr: string): T
{
return actionStr as T; // does not work
}
export enum ActionEnum {
Unknown = 0,
Sleep = 1,
Run
}
let action: ActionEnum = getMethodEnum<ActionEnum>()
我在TypeScript中有一个字符串枚举,我想像下面这样迭代它。但是,当我这样做时,迭代器的类型是一个字符串,而不是枚举类型。 enum Enum { A = 'a', B = 'b' };
let cipher: { [key in Enum]: string };
for (const letter in Enum) {
cipher[letter] = 'test'; // error: letter is of type 'string' but needs to be 'Enum'
} 我
碰巧,用户点击enter,我不想把它作为输入的一部分,字符串可以以3次结束\n,所以只替换一个就不能完成我的解决方案;
String values[] = string_Ends_With_Back_Slash_N.split("\n");
String String_without_Back_Slash_N =new String (values [0]);
//or just to point there without the new but i want later to dump the garbage.
或者至少现在将值转储到gc .
所以两个问题:
有更有效的方
public enum Color
{
Red = 'R',
Blue = 'B',
Green = 'G',
Yellow = 'Y',
}
Color color = (Color)Enum.Parse(typeof(Color), "R");
你好社区!
我试图用char解析一个字符串值,但它抛出了一个System.ArgumentException。
(预先谢谢:)
我在TypeScript中定义了以下枚举:
enum Color{
Red, Green
}
现在,在我的函数中,我以字符串的形式接收颜色。我已经尝试了以下代码:
var green= "Green";
var color : Color = <Color>green; // Error: can't convert string to enum
如何将该值转换为枚举?