List<Object> testimonials = new List<Object>();
testimonials.Add(new {
Author = "Author 1",
Testimonial = "Testimonial 1"
});
testimonials.Add(new {
Author = "Author 2",
Testimonial = "Testimonial 2"
});
testimonials.Add(new {
Author = "Author 3",
Testimonial = "Testimonial 3"
});
@ObjectInfo.Print(testimonials[DateTime.Now.DayOfYear % testimonials.Count].Author)
Gives me an error CS1061: ‘object’ does not contain a definition for ‘Author’
How do I get only the Author or Testimonial from the list of testimonials?
A lazy way would be to switch “object” for “dynamic”. Or use A Tuple generic type.
But IMO you should simply write a class with hear two properties:
And use a List-of-Testimonial.
Another way would be to use something like:
This is an array of your anon-type, and;
Would work fine.