Error Messge:
C:\USR\Dev\C#\DateInheritance.cs(15): The type or namespace name 'Date'
could not be found (are you missing a using directive or an assembly
reference?)
Thanks,
Victor
=================================
using System ;
class DateInheritance
{
public static void Main()
{ ...}
}
class DatePlus : Date <---------- Problematic line
{ public DatePlus() {}
public DatePlus(int year, int month, int day): base(year, month, day) {}
public int DaysSince1600
{ ... } // properties
public override string ToString()
{ ... }
public static int operator -(DatePlus date1, DatePlus date2)
{ ... }
}
"Victor" <vmgoldberg__NO-_*SPAM*_-PLE...@earthlink.net> wrote in message
news:Pr6pc.9531$KE6....@newsread3.news.atl.earthlink.net...
Well, what class are you trying to derive from? There is no Date class
as far as I know.
If you meant DateTime, should should realise that that's a struct, so
you can't derive from it.
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Victor
Assuming you're using VS.NET, you add a reference to an assembly by
right-clicking on the "References" item in the project.
You tell the compiler you wish to use a specific namespace by putting
using TheNamespaceIWant;
at the top of your source code.
I am following Charles Petzold's book "Programming Microsoft Windows with
C#", page 41.
Also, I have successfully used Date as type for variables definitions.
What I cannot understand is why is it that I cannot inherit from it in this
specific code sample.
I guess if he wrote code using the Date class, he knows what's he talking
about.
In addition to that, when I try DateTime I get the following error:
C:\USR\Dev\C#\DateInheritance.cs(15): 'DatePlus' : cannot inherit from
sealed class 'System.DateTime'
Victor
"Jon Skeet [C# MVP]" <sk...@pobox.com> wrote in message
news:MPG.1b0f08c6a...@msnews.microsoft.com...
Unfortunately, my copy of that book is at work.
> Also, I have successfully used Date as type for variables definitions.
I seriously doubt that, unless you've defined Date in the same project
- which Petzold may well have done.
Could you post a short but complete program which demonstrates using
the Date class, and which compiles without you also including the Date
class itself?
> What I cannot understand is why is it that I cannot inherit from it in this
> specific code sample.
>
> I guess if he wrote code using the Date class, he knows what's he talking
> about.
Unfortunately, in my experience code in books often doesn't compile.
Alternatively, as suggested above, he's included his own Date class.
Date is most definitely *not* a type in the main framework though.
> In addition to that, when I try DateTime I get the following error:
> C:\USR\Dev\C#\DateInheritance.cs(15): 'DatePlus' : cannot inherit from
> sealed class 'System.DateTime'
Yes, because as I said, DateTime is a struct, so you can't derive from