Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The type or namespace name 'Date' could not be found

0 views
Skip to first unread message

Victor

unread,
May 14, 2004, 12:27:27 PM5/14/04
to
When building a C# project in VS (compacted code included here), I get the
following error message.
What does it mean, and what should I do to overcome the problem?

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)
{ ... }
}


Peter Rilling

unread,
May 14, 2004, 12:36:34 PM5/14/04
to
Make sure that the correct assembly is referenced and that you import the
correct namespace.

"Victor" <vmgoldberg__NO-_*SPAM*_-PLE...@earthlink.net> wrote in message
news:Pr6pc.9531$KE6....@newsread3.news.atl.earthlink.net...

Jon Skeet [C# MVP]

unread,
May 14, 2004, 12:48:48 PM5/14/04
to
Victor <vmgoldberg__NO-_*SPAM*_-PLE...@earthlink.net> wrote:
> When building a C# project in VS (compacted code included here), I get the
> following error message.
> What does it mean, and what should I do to overcome the problem?

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

unread,
May 14, 2004, 12:58:39 PM5/14/04
to
Thank you, Peter.
How do I do that?

Victor

Jon Skeet [C# MVP]

unread,
May 14, 2004, 1:02:58 PM5/14/04
to
Victor <vmgoldberg__NO-_*SPAM*_-PLE...@earthlink.net> wrote:
> Thank you, Peter.
> How do I do that?

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.

Victor

unread,
May 14, 2004, 1:22:32 PM5/14/04
to
Thank you, Jon.

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...

Jon Skeet [C# MVP]

unread,
May 14, 2004, 1:33:48 PM5/14/04
to
Victor <vmgoldberg__NO-_*SPAM*_-PLE...@earthlink.net> wrote:
> Thank you, Jon.
>
> I am following Charles Petzold's book "Programming Microsoft Windows with
> C#", page 41.

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

0 new messages