c# - Store anonymous values in a list and extract each individually -


i'm trying store information in block of anonymous values

//holds info var jobs = new { newjob, numbytes, requiredtime }; 

then take information , place list single element

//puts above info list joblist.add(convert.tostring(jobs)); console.writeline(joblist[0]);   //testing purposes 

now able call joblist , take value of example numbytes @ position 4.

is possible? or alternate way of doing this? thanks!

the "normal" thing in c# create class hold information want store. example:

public class job {     public string name { get; set; }     public int numbytes { get; set; }     public datetime requiredtime { get; set; } } 

then can add these list:

var jobs = new list<job>();  var ajob = new job(); ajob.name = "job 1"; ajob.numbytes = 123;  jobs.add(ajob); 

then can access jobs index in list:

var jobnumbytes = jobs[3].numbytes; 

one thing note c#, when do:

new { newjob, numbytes, requiredtime }; 

the compiler, @ build time, creates typed class (just job class created above) , generates random name it. infers property names , types variables assigning it. created .exe or .dll contain class definition type, can't other places in code. isn't "dynamic". using syntax lazy way of declaring class need moment. inside 1 method, don't need more. creating named class want do.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -