How can we find items count in the C# integer array? -


i need find items count in c# array type integer.

what mean is;

int[] intarray=new int[10] int[0]=34 int[1]=65 int[2]=98 

items count intarray 3.

i found code strarray below doesn't work int arrays.

string[] strarray = new string[50]; ... int result = strarray.count(s => s != null); 

well, first have decide invalid value be. 0? if so, this:

int result = intarray.count(i => != 0); 

note works because, default, elements of int array initialized zero. you'd have fill array different, invalid value beforehand if 0 ends being valid in situation.

another way use nullable type:

int?[] intarray = new int?[10]; intarray[0] = 34; intarray[1] = 65; intarray[2] = 98;  int result = intarray.count(i => i.hasvalue); 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -