-3

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
2
  • You mean you need to make an array in C# Commented Jun 28, 2015 at 0:56
  • you cant give string to array as index. so i think dictionary is the best choice. @hoss Commented Jun 28, 2015 at 0:59

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

Yes a,a2,a3,.. are strings.
so this is what you need. @binuj
0

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

2 Comments

its not class. in JavaScript. Its called associative array
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#

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.