Arraylist.contains error

private ArrayList alphabets = new ArrayList{“A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”, “J”, “K”, “L”, “M”, “N”, “O”, “P”, “Q”, “R”, “S”, “T”,“U”, “V”, “W”, “X”, “Y”, “Z”};

in function i written. aWord is a 3 letter word

	for(w = 0; w < aWord.Length; w++ ){
		wordList.Add(aWord[w]);
		showList.Add(aWord[w]);
	}
	

	do
		{ 
		 	string wor = alphabets[Random.Range(0, alphabets.Count)] as string;
			if (showList.Contains(wor))
		    {  
				print(wor);		    	
		    }
		else{
			showList.Add(wor);		
		}

		} while (showList.Count < 5);

Contains not working properly.why it so

That’s because ArrayList.Contains doesn’t do what you think it does.

ArrayList is a list of objects, not strings. It performs boxing and unboxing when you add to it and read from it. Its Contains method is implemented to check whether a given object instance exists in the list, see this page and notice especially that it does comparison using Object.Equals. That compares two object references. It does not compare two strings.

You shouldn’t use ArrayList anyway, since it is a .Net 2.0 collection which has largely been superceded by the more effective generic List. The generic List’s Contains method will do what you want, because it uses the type specific Equals method defined by whatever type you stick in it, String in this case, and not by Object.