开发者

C# "An object reference is required for the non-static field, method, or property"

Having the same issue i was last week only with inheiriting from the parent class:

public ExtendedTime(int Hour, int Minute, String TimeZone) :base(hour, minute)
{

    timeZone = TimeZone;
}//end of ExtendedTime

:base(hour,minute) is where i have this error. Says the same problem for both hour and minute. Now usually I would say that i'm missing something far as a property but i tried that and it didn't do any good sadly.

in th开发者_高级运维e parent class hour and minute are declared as following:

    internal int hour;
    internal int minute;

And i have setters and getters setup.


You're trying to use the fields hour and minute when you probably meant to use the constructor parameters. You can't use fields (or any other instance members) when calling a base class constructor.

Personally I'd change the constructor parameters to have more conventional names:

public ExtendedTime(int hour, int minute, String timeZone) : base(hour, minute)
{    
    this.timeZone = timeZone;
}

Note that if you made your fields private instead of internal, the issue would have been more obvious, as you wouldn't have access to the fields in the first place :)


You're not passing your arguments:

Hour != hour
Minute != minute

Change it to

public ExtendedTime(int hour, int minute, string timeZone) : base(hour, minute)


I think you might be having a casing problem (c# is case sensitive), try this:

public ExtendedTime(int hour, int minute, String TimeZone) :base(hour, minute)


Clearly, int Hour, int Minute, String TimeZone are not proper parameters. Use object names in parameters, not their Class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜