I have the following switch
statement (with this syntax that's new to me).
I also have the following Dictionary
/ Enum
in a static class.
Switch
statement :
public static Dictionary<string, string> MyMethod(string brands, int templateIndex, long accountId)
{
return accountId switch
{
AccountsId[AccountLang.French] => Fr.GetContent(templateIndex, brands),
AccountsId[AccountLang.Spanish] => ES.GetContent(templateIndex, brands),
_ => throw new Exception($"Account Id not found {typeof(LangHelper)}")
};
}
Dictionary
/ Enum
:
public static readonly Dictionary<AccountLang, long> AccountsId = new Dictionary<AccountLang, long>()
{
{AccountLang.French , 25****** },
{AccountLang.Spanish , 55****** },
};
public enum AccountLang
{
French,
Spanish,
}
And here are the 3 errors I have all of them for AccountsId[AccountLang.French]
in the switch case:
Error CS0246 The type or namespace name 'AccountsId' could not be found (are you missing a using directive or an assembly reference?)
Error CS8121 An expression of type 'long' cannot be handled by a pattern of type 'AccountsId[]'.
Error CS0270 Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
If I the switch case with this syntax I have the same error but on compilation :
long aId when AccountsId[AccountLang.French] == aId => Fr.GetContent(templateIndex, brands)
If I place the namespace and class like this NamespaceName.className.NameAccountsId
its the same problem
What I am missing here looks like the first issue comes because it cannot find AccountsId
dictionary but if I use it outside he switch case it works perfectly.