I have a class, and when I try to use it in another class, I get the error below.
using System; using System.Collections.Generic; using System.Linq; namespace MySite { public class Reminders { public Dictionary<TimeSpan, string> TimeSpanText { get; set; } // We are setting the default values using the Costructor public Reminders() { TimeSpanText.Add(TimeSpan.Zero, "None"); TimeSpanText.Add(new TimeSpan(0, 0, 5, 0), "5 minutes before"); TimeSpanText.Add(new TimeSpan(0, 0, 15, 0), "15 minutes before"); TimeSpanText.Add(new TimeSpan(0, 0, 30, 0), "30 minutes before"); TimeSpanText.Add(new TimeSpan(0, 1, 0, 0), "1 hour before"); TimeSpanText.Add(new TimeSpan(0, 2, 0, 0), "2 hours before"); TimeSpanText.Add(new TimeSpan(1, 0, 0, 0), "1 day before"); TimeSpanText.Add(new TimeSpan(2, 0, 0, 0), "2 day before"); } } }
Using a class in another class
class SomeOtherClass { private Reminders reminder = new Reminders();
Error (CS0236):
A field initializer cannot reference the nonstatic field, method, or property
Why is this happening and how to fix it?
c #
GibboK Jan 21 '13 at 13:01 2013-01-21 13:01
source share