G
Guest
Hi community,
Based on the promise that classes developed in C# and compiled into a *.dll
can be used from a VB.Net project I tried the following:
I need to develop a class PeriodDate in which I hold an integer representing
a PeriodDate in the format 200410 (where 2004 is the year and 10 is the
month). It happens that I have to make comparisons and would like to use
following VB code
Dim x as PeriodDate = new PeriodDate(200410)
Dim y as PeriodDate = new PeriodDate(200409)
If y < x then …
As far as I know operators cannot be implemented in VB.Net classes, however,
it can be done in C#.
Logically I created a C# project (class library) created a class PeriodDate
and implemented two operators
public static bool operator >(PeriodDate a, PeriodDate b) {
if ( a.PeriodNumber > b.PeriodNumber ) return true;
return false;
}
public static bool operator <(PeriodDate a, PeriodDate b) {
if ( a.PeriodNumber < b.PeriodNumber ) return true;
return false;
}
I compiled the dll, made the appropriate references in the VB.Net project
and used it in VB.Net as described above. This causes the IDE / compiler to
through the following error message:
“Operator ‘<’ not defined for types …â€
Am I overseeing something or is this an illegal design concept?
Any help is appreciated.
Regards,
Christian
Based on the promise that classes developed in C# and compiled into a *.dll
can be used from a VB.Net project I tried the following:
I need to develop a class PeriodDate in which I hold an integer representing
a PeriodDate in the format 200410 (where 2004 is the year and 10 is the
month). It happens that I have to make comparisons and would like to use
following VB code
Dim x as PeriodDate = new PeriodDate(200410)
Dim y as PeriodDate = new PeriodDate(200409)
If y < x then …
As far as I know operators cannot be implemented in VB.Net classes, however,
it can be done in C#.
Logically I created a C# project (class library) created a class PeriodDate
and implemented two operators
public static bool operator >(PeriodDate a, PeriodDate b) {
if ( a.PeriodNumber > b.PeriodNumber ) return true;
return false;
}
public static bool operator <(PeriodDate a, PeriodDate b) {
if ( a.PeriodNumber < b.PeriodNumber ) return true;
return false;
}
I compiled the dll, made the appropriate references in the VB.Net project
and used it in VB.Net as described above. This causes the IDE / compiler to
through the following error message:
“Operator ‘<’ not defined for types …â€
Am I overseeing something or is this an illegal design concept?
Any help is appreciated.
Regards,
Christian