Need equivalent code in C# or vb.net for this javascript code.
var rules = {
a: 'അ',
a2: 'ആ',
a3: 'എ',
aa: 'ആ',
A2: 'ആ',
A3: 'എ',
i: 'ഇ',
i2: 'ഈ',
i3: 'ഐ'
};
var pattern = rules["a"];
asked Jun 28, 2015 at 0:41
binu j
3991 gold badge3 silver badges18 bronze badges
-
You mean you need to make an array in C#hoss– hoss2015年06月28日 00:56:40 +00:00Commented Jun 28, 2015 at 0:56
-
you cant give string to array as index. so i think dictionary is the best choice. @hossM.kazem Akhgary– M.kazem Akhgary2015年06月28日 00:59:24 +00:00Commented Jun 28, 2015 at 0:59
2 Answers 2
In C# Use Dictionary.
Dictionary<string, char> rules = new Dictionary<string, char>
{
{a, 'അ'},
{a2, 'ആ'},
{a3, 'എ'},
{aa, 'ആ'},
{A2, 'ആ'},
{A3, 'എ'},
{i, 'ഇ'},
{i2, 'ഈ'},
{i3, 'ഐ'}
};
var pattern = rules["a"];
I assumed that type of a,a2,a3,... is string as you didnt mentioned what are the types.
What you have is called Associative arrays. See here.
The closest Alternative in C# is Dictionary. Where you can give object as key and Get value.
answered Jun 28, 2015 at 0:51
M.kazem Akhgary
19.3k8 gold badges68 silver badges126 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
binu j
Yes a,a2,a3,.. are strings.
M.kazem Akhgary
so this is what you need. @binuj
You need to be more explicit with what you are trying to do exactly, but this would compile under certain circumstances:
class Chars
{
public char a;
public char a2;
public char a3;
public char aa;
public char A2;
public char A3;
public char i;
public char i2;
public char i3;
}
Chars rules = new Chars {
a= 'അ',
a2= 'ആ',
a3= 'എ',
aa= 'ആ',
A2= 'ആ',
A3= 'എ',
i= 'ഇ',
i2= 'ഈ',
i3= 'ഐ'
};
char pattern = rules.a;
answered Jun 28, 2015 at 0:49
maraaaaaaaa
8,2013 gold badges25 silver badges42 bronze badges
2 Comments
M.kazem Akhgary
its not class. in JavaScript. Its called associative array
maraaaaaaaa
thats why you have to be more detailed with what you are trying to do... theres 20 different ways you can reformat that for C#
default