473,657 Members | 2,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing the implementing class when only an Interface reference is available - relatively new to C#

Hi, I'm just getting my feet wet with C# and need some help with interface
implementation.
I want to create a collection of various objects that implement a certain
interface (i.e. IMyInterface). Each object will have additional methods
which are unique to their class. The collection will only accept types
IMyInterface but I want to be able to access any object in the collection
via the interface or the implementing class. Is this possible when the
collection only holds objects of type IMyInterface? Thanks for the help.

Devon
Nov 15 '05 #1
1 1343
Jeff and Devon,

It should also be noted that this generally is a bad idea, because you
are circumventing the whole idea of having interfaces.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Jeff Louie" <je********@yah oo.com> wrote in message
news:eK******** ******@tk2msftn gp13.phx.gbl...
Devon... For a given object in the collection, you should be able to
cast
the returned reference to a valid type supported by the given object.

http://www.geocities.com/jeff_louie/OOP/oop6.htm.

Regards,
Jeff
I want to create a collection of various objects that implement a

certain
interface (i.e. IMyInterface). Each object will have additional
methods
which are unique to their class. The collection will only accept types
IMyInterface but I want to be able to access any object in the
collection
via the interface or the implementing class.<

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #2

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

Similar topics

2
398
by: Paul | last post by:
Have a problem/Question - I have created a C# class that inherits from MarshalByRefObject as well as implements a custom Interface that I have created. The thing that is not working is that when I try to use this class in a different assembly I cannot reference it even when using it's namespace qualifier. It has been refereced in my project. I even put the namespace in the Imports/using statements in the top of the class file (I've...
5
2184
by: Paul | last post by:
OK...I must be missing something...can someone tell me what I'm not doing properly... First, create an assembly with a single interface in VB.NET as follow Public Interface IDo Function Bark(ByVal lVolume As Long) As Strin End Interfac Pretty simple..
6
2752
by: Martyn Lawson | last post by:
Hi, I am currently working as an Analyst on a .NET Web Project using ASP.NET and C#.NET. I have a couple of, at least what should be, quick questions: 1. My understanding of UML says that the Controller classe of a Sequence Diagram should be implemented as a private class within a component. However, my Programmer has said that since the ASP code lives outside the
6
2154
by: TB | last post by:
I understand the basics of finalization and implementing IDisposable and how one is guaranteed access to managed objects only when working through the IDisposable interface. My question is to what extent can I rely on access to my private data during the finalization process when *not* coming through the IDisposable interface? Are private members still valid or are they managed objects that may already be gone? Are some types accessible...
2
1766
by: Sergey Romanov | last post by:
I have two window app. I have Tree in main window and in code of that window I have function BuildTree(); This function start with tree.Clear(); So it completely rebuild tree. When I open other window as dialog after clicking on `Save` button I whant call BuildTree() function. Sorry, I am jus a biginer. How am I suupoused to do that? An yet I whant change lable text on main window. How to access lable control on main form from dialog...
4
5080
by: John C | last post by:
I'm new to C#, so just point me at the correct reference material if this question has been answered before. When creating a new class which implements the IDictionary interface, two versions of the GetEnumerator method must be defined (one from the IDictionary interface, one from the IEnumerable interface). The first is defined as: public IDictionaryEnumerator GetEnumerator()
4
1418
by: John | last post by:
I am having a problem accessing the members in a structure via an interface and Class. ***Development Code*** Structure Person Public Name as String End Structure Interface IData Public Property Employee As Person
6
3981
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public string UID; public string PWD; }
0
2026
by: Roger Stoller | last post by:
Hello. I have developed a COM object using ATL. It seems to work fine when accessing it from VB.NET most of the time. However, I want to use a delegate in VB to asynchronously run a method in one of the interfaces in my COM module (using Delegate.BeginInvoke()). The interface seems to be "junk" when accessing it from the delegated VB method. When called synchronously from the same thread using the Delegate.Invoke(), it seems to work...
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8518
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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 we have to send another system

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.