473,505 Members | 15,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Implicit conversion of arrays

If I have two types, t1 and t2, say, I can write an implicit
conversion operator from t1 to t2.

Can I write implicit conversion operator from t1[] to t2[]?

I don't think I can... but, if not, what is the "next nicest thing"?

--
Clive Tooth
http://www.shutterstock.com/cat.mhtml?gallery_id=61771
Jun 27 '08 #1
4 2895
"The Last Danish Pastry" <cl****@gmail.comwrote in message
news:69*************@mid.individual.net...
If I have two types, t1 and t2, say, I can write an implicit
conversion operator from t1 to t2.

Can I write implicit conversion operator from t1[] to t2[]?

I don't think I can... but, if not, what is the "next nicest thing"?
I should have mentioned that I am talking about C#.

--
Clive Tooth
http://www.shutterstock.com/cat.mhtml?gallery_id=61771
Jun 27 '08 #2
The Last Danish Pastry wrote:
"The Last Danish Pastry" <cl****@gmail.comwrote in message
news:69*************@mid.individual.net...
>If I have two types, t1 and t2, say, I can write an implicit
conversion operator from t1 to t2.

Can I write implicit conversion operator from t1[] to t2[]?

I don't think I can... but, if not, what is the "next nicest thing"?

I should have mentioned that I am talking about C#.
If you're using .NET 3.5, you could write an extension method.

If not, then you'll have to just write a static method somewhere.

--
Lasse Vågsæther Karlsen
mailto:la***@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
Jun 27 '08 #3
The Last Danish Pastry wrote:
If I have two types, t1 and t2, say, I can write an implicit
conversion operator from t1 to t2.

Can I write implicit conversion operator from t1[] to t2[]?

I don't think I can... but, if not, what is the "next nicest thing"?
What are you using the arrays for?

Would it make sense to wrap them in a (perhaps generic) class or struct
with an indexing operator ('this' property)? You can add implicit
conversions to classes and structs.

-- Barry

--
http://barrkel.blogspot.com/
Jun 27 '08 #4
On Mon, 26 May 2008 06:45:12 -0700, Lasse Vågsæther Karlsen
<la***@vkarlsen.nowrote:
>>[...]
Can I write implicit conversion operator from t1[] to t2[]?

I don't think I can... but, if not, what is the "next nicest thing"?
I should have mentioned that I am talking about C#.

If you're using .NET 3.5, you could write an extension method.
And if the requirement is somewhat "looser", and you don't really need an
array per se as the output, but rather just something you can enumerate,
you could even use the LINQ Cast<Tmethod.

But as Lasse said, no implicit conversions.

Pete
Jun 27 '08 #5

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

Similar topics

2
3077
by: Russell Reagan | last post by:
In a newer version of a chess program I am writing, I have created classes that are (more or less) drop in replacements for things that used to be plain old integer or enumerated variables (colors,...
1
1845
by: Christophe Poucet | last post by:
Hellom I have an issue with implicit conversions. Apparently when one calls an operator on a class Y which has a conversion operator to class X which has the operator . Sadly it will not do...
11
7590
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
9
2061
by: Girish | last post by:
Im trying to understand implicit type conversions from object -> string and vice versa. I have two classes, one Driver and one called StringWrapper. These are just test classes that try and...
11
12713
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
36
3589
by: Chad Z. Hower aka Kudzu | last post by:
I have an implicit conversion set up in an assembly from a Stream to something else. In C#, it works. In VB it does not. Does VB support implicit conversions? And if so any idea why it would work...
10
2177
by: Pieter Breed | last post by:
Hi All, Please excuse me, but the bulk of my post will be a code post. It describes some weirdness with regards to the implicit casting operator. The crux of the problem is this: I want to...
82
4538
by: robert bristow-johnson | last post by:
here is a post i put out (using Google Groups) that got dropped by google: i am using gcc as so: $ gcc -v Using built-in specs. Target: i386-redhat-linux Configured with: ../configure...
8
5645
by: jonpb | last post by:
Hi, Is it possible to define a implicit operator from base to derived types in C#? I have a Point class and would like to derive a Vector class from it and add a couple new vector related...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.