How can I acces this?

  • Thread starter Thread starter Arjen
  • Start date Start date
A

Arjen

Hello,

Let's see this sample code.

Here is the main.
<cut>
namespace A {
/// <summary>
/// Singleton
/// </summary>
class A {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args) {

Persons persons = new Persons();
</cut>

Here is class b.
<cut>
public class B {
public bool PersonManager() {
IDictionaryEnumerator iter = persons.GetEnumerator();

</cut>

Now "persons.GetEnumerator();" is not working because it is not accesable.
How can I acces it? I must use it inside class a and I need exacly the same
one.

Many Thanks!
 
Arjen,

Without seeing the definition of the Persons class, it is hard to tell.
If class B is not in the same assembly that the Persons class is in, then
you will have to expose the GetEnumerator method as public. However, I am
guessing that you might have an implicit interface implementation of the
IEnumerable interface, in which case you can cast the Persons instance to
IEnumerable and then make the call.

If you are not implementing IEnumerable, and B is in the same assembly
as the Persons class, then you will have to declare the GetEnumerator method
as protected, so that other classes in the same assembly may access the
method.

Hope this helps.
 
All right!
Thanks!



Nicholas Paldino said:
Arjen,

Without seeing the definition of the Persons class, it is hard to tell.
If class B is not in the same assembly that the Persons class is in, then
you will have to expose the GetEnumerator method as public. However, I am
guessing that you might have an implicit interface implementation of the
IEnumerable interface, in which case you can cast the Persons instance to
IEnumerable and then make the call.

If you are not implementing IEnumerable, and B is in the same assembly
as the Persons class, then you will have to declare the GetEnumerator method
as protected, so that other classes in the same assembly may access the
method.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Arjen said:
Hello,

Let's see this sample code.

Here is the main.
<cut>
namespace A {
/// <summary>
/// Singleton
/// </summary>
class A {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args) {

Persons persons = new Persons();
</cut>

Here is class b.
<cut>
public class B {
public bool PersonManager() {
IDictionaryEnumerator iter = persons.GetEnumerator();

</cut>

Now "persons.GetEnumerator();" is not working because it is not accesable.
How can I acces it? I must use it inside class a and I need exacly the same
one.

Many Thanks!
 
Back
Top