c# - How to place and access an object of type class within a queue -


so have job class

public class job {    private string id;                   private int numbytes;               private int requiredtime;  } 

within main receive values , create job

var ajob = new job(); queue jobqueue = new queue(); 

i want able take job info out of queue job again

job test = new job();            test = (job)jobqueue.peek(); 

however when print out recieve "job"

console.writeline(test); 

i've recieved compiler error when use:

test = jobqueue.peek(); error 1 cannot implicitly convert type 'object' 'job'. explicit conversion exists      (are missing cast?) 

basically goal here store jobs in queue , access job's individual properties.

much thanks!

first, you'll want use queue<job>. non-generic version old versions of .net framework shouldn't use new code more.

second, can't print properties (they not called attributes) of custom class calling console.writeline(). you'll need print them individually, like:

console.writeline("id = {0}", test.id); console.writeline("numbytes = {0}", test.numbytes); console.writeline("requiredtime = {0}", test.requiredtime); 

or override tostring() method described other answer.


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 -