473,409 Members | 2,004 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,409 software developers and data experts.

Collections and implicit cast

hi,

Let's suppose I've got 2 classes: MyClass and MyClassColl (coll is inherited
from ArrayList, for instance). But, when I invoke GetXXX or something
returning object, I receive an object - not instance of MyClass. I've tried
with implicit conversions - not working.

Is there any way to inherit some collection that will have instances of
custom class and make implicit conversion for return values? Practically, I
need typed collection. Because there's no such thing in C#, I'm trying to
find workaround. Can implicit conversions help me? This thing would save lot
of effort.

thanks in advance,
bj
Nov 15 '05 #1
1 1644
Bratislav,

Implicit conversions would not help you. The easiest (but tedious) way
of doing this is deriving from the CollectionBase class. You will have to
create type-safe versions of accessor methods and the like. However, the
implementations of the enumerator, and interface implementations are
handled.

However, with Generics, this will become very, very easy, but we will
have to wait for that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bratislav Jevtic" <in*******@ptt.yu> wrote in message
news:Ow**************@TK2MSFTNGP11.phx.gbl...
hi,

Let's suppose I've got 2 classes: MyClass and MyClassColl (coll is inherited from ArrayList, for instance). But, when I invoke GetXXX or something
returning object, I receive an object - not instance of MyClass. I've tried with implicit conversions - not working.

Is there any way to inherit some collection that will have instances of
custom class and make implicit conversion for return values? Practically, I need typed collection. Because there's no such thing in C#, I'm trying to
find workaround. Can implicit conversions help me? This thing would save lot of effort.

thanks in advance,
bj

Nov 15 '05 #2

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

Similar topics

4
by: Simon Ford | last post by:
Hi All, I'm having trouble understanding exactly how I can do some specific implicit casting. There are two problems here; does anyone know what I should be doing? //---------- // (1)...
10
by: Peter Drese | last post by:
Hello, I have to write an exam and I am not sure about implicit typecasting. Can somebody please tell me of what type the following c-statements are? And why they are of this type? It is also...
15
by: buda | last post by:
Let me see if I got this :) 1. I know the rules for type conversions in arithmetic expressions 2. I know that an implicit type conversion is done at assignment, so float x = 1.23; int t = (int)...
11
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
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...
10
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...
17
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
1
by: not_a_commie | last post by:
I have an Angle class that I store angles in. It's basically just a bunch of fancy functions for manipulating a double. It has implicit casts for converting to/from double. Due to the project...
17
by: arnuld | last post by:
I have checked the FAQ: http://c-faq.com/malloc/mallocnocast.html FAQ discusses a special case when programmer has forgotten to do #include <stdlib.h>. I am including this header and I am not...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.