473,385 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Collaboration between C# and VB.Net

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

Jul 21 '05 #1
3 1225
Hi,

From what I understand, .NET has a thing called the Common Language
Specification, which is the "bare" minimum any language needs to implement
when working with the .NET framework. Operator overloading is NOT part of
this specification, and VB.NET cannot handle it..

The common approach is to have your class implement IComparable. This has a
method CompareTo which returns an int.

Basically, make sure that you stick within the CLS and you will be fine
operating between different languages.

I hope this helps even a little.

"Christian" wrote:
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

Jul 21 '05 #2
In VB.NET 2003, you must access the < operator via "op_LessThan"
for all but 'core' data type cases.

(ditto for op_GreaterThan, op_Equality, etc.)

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Jul 21 '05 #3
Dear Eddie,

thanks for your answer, this solves my problem

Regards,
Christian

"Eddie de Bear" wrote:
Hi,

From what I understand, .NET has a thing called the Common Language
Specification, which is the "bare" minimum any language needs to implement
when working with the .NET framework. Operator overloading is NOT part of
this specification, and VB.NET cannot handle it..

The common approach is to have your class implement IComparable. This has a
method CompareTo which returns an int.

Basically, make sure that you stick within the CLS and you will be fine
operating between different languages.

I hope this helps even a little.

"Christian" wrote:
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

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: marcoanyway | last post by:
Hi all! I would like to know if it's possible to customize the layout of the Collaboration Suite. I mean if it's possible to give to the user a different appearence than the standard Oracle one....
29
by: Bill Marsden | last post by:
Hi. I am an under-graduate currently studying Open Source (Linux) vs Closed Source and Collaboration within the IT Community. I am fairly new to Javascript and I have written a "Lottery Program"...
0
by: Pat Sinnott | last post by:
Hi, I am attempting to create a mapi session with an ASP.net page with the following code: Dim oSess As New MAPI.Session() oSess.Logon("MS Exchange Settings")
0
by: SPE - Stani's Python Editor | last post by:
Dear Pythoneers, Looking at IDE's I can have three observations: 1. For some reasons numerous users prefer to use an open source IDE. 2. For some reasons numerous python programmers like to...
0
by: marcoanyway | last post by:
Hi all! I would like to know if it's possible to customize the layout of the Collaboration Suite. I mean if it's possible to give to the user a different appearence than the standard Oracle one....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.