Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare array of strings with string index?

Tags:

arrays

string

c#

In my code i declared like this :

public string[] s ;

and i need to use this string like this :

s["Matthew"]="Has a dog";
s["John"]="Has a car";

when i use s["Matthew"] an error appears and it says "Cannot implicitly convert 'string' to 'int'" . How can I make a string array to have string index ? if i write this in php it works :

array() a;
a["Mathew"]="Is a boy";

I need it to work also in asp.net !

like image 963
Stefan P. Avatar asked Dec 08 '22 08:12

Stefan P.


1 Answers

public Dictionary<string, string> s;

MSDN documentation

like image 62
Christian Hayter Avatar answered Dec 11 '22 06:12

Christian Hayter