Why can't I do this (or can I) ?

I

Ian Semmel

I haven't used interfaces before, but I thought I'd come across a reason
for using them.



Suppose I have :



public interface ILogger

{

void LogLine(string s);

void LogLine(object o);

}



and somewhere else I have :



public abstract class Log : ILogger

{

public void LogLine ( string s ) { . }

public void LogLine ( object o ) { . }

}



So far so good.



Now if later on again I declare :



protected ILogger log;



I can write statements



log.LogLine ( "sss" );



This all compiles OK.

BUT



It appears I can's set a property



public ILogger

{

set { log = value; }

}



What I'm trying to do is use the same code for WindowsForms and Web
code. The logging method is different for both.



I presume I can use abstract classes, but this is what I thought
interfaces were for.
 
?

=?windows-1252?Q?G=F6ran_Andersson?=

Ian said:
I haven't used interfaces before, but I thought I'd come across a reason
for using them.

Suppose I have :

public interface ILogger
{
void LogLine(string s);
void LogLine(object o);
}

and somewhere else I have :

public abstract class Log : ILogger
{
public void LogLine ( string s ) { … }
public void LogLine ( object o ) { … }
}

So far so good.

Now if later on again I declare :

protected ILogger log;

I can write statements

log.LogLine ( "sss" );

This all compiles OK.
BUT

It appears I can's set a property

public ILogger
{
set { log = value; }
}

What I'm trying to do is use the same code for WindowsForms and Web
code. The logging method is different for both.

I presume I can use abstract classes, but this is what I thought
interfaces were for.

You need a name for your property:

public ILogger Log {
set { log = value; }
}
 
I

Ian Semmel

You need a name for your property:

public ILogger Log {
set { log = value; }
}

My error was even dumber than that.

I actually was trying to type in

get { log = value; }

and was wondering why it didn't work.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Ian said:
My error was even dumber than that.

I actually was trying to type in

get { log = value; }

and was wondering why it didn't work.

Well, I can only see the errors in the code that you actually post... ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top