c# - List with int array - accessing the array -


i have class (students) 2 strings , int array

a second class this:

list<student> mys = new list<student>(); 

all of works correctly , have list containing multiple students. having difficulty accessing values within int[].

so, student list populated database , list.

i have generic class has parameter list want data table. generic class called student class, subjects class , other classes - of may contain arrays , not.

if debug , step through, following: (() mys.stu[6].termmark[1] , value 50. if enter int d =stu[6].termmark[1] error t not contain definition termmark , no extension method 'termmark' accepting first argument of type t found.

int d = mys[0][1] returns error

cannot apply indexing [] expression of type 't'

. have tried various things creating separate list , adding mys. nothing works.

thanks in advance help.

i new , missing obvious...

you must read generic constraints
cannot argument of type t.
if function accepts arguments of type student , add constraint this

private static void newmethod<t>(list<t> mys) t : student {         int d = mys[0].intarray[1]; } 

the following not related problem...
if add indexer class can make little shorter

public class student {     public int[] intarray;      public int this[int x]     {                 {             return intarray[x];         }     } } private static void newmethod<t>(list<t> mys) t : student {         int d = mys[0][3];  } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -