am i Ld?

bpayne111

Junior Contributor
Joined
Feb 28, 2003
Messages
325
Location
BFE
C#:
public interface myPlug
	{
		void Initialize(test.IHost host);
		readonly string Name();
		void Go(object[] objs);
	}

blue squiggly on 'Name'
"The modifier 'readonly' is not valid for this item"

Why? what's wrong with this?

i feel small
Brandon
 
bpayne111 said:
C#:
public interface myPlug
    {
        void Initialize(test.IHost host);
        readonly string Name();
        void Go(object[] objs);
    }

blue squiggly on 'Name'
"The modifier 'readonly' is not valid for this item"

Why? what's wrong with this?

i feel small
Brandon

if I understand correctly want you really want is a read only property in your interface. . .

PHP:
public interface myPlug
	{
		void Initialize(test.IHost host);
		string Name { get{} };
		void Go(object[] objs);
	}
 
thansk for you your help... i figured it out after some more time
i just used a function instead of a readonly property... DOH!
 
bpayne111 said:
thansk for you your help... i figured it out after some more time
i just used a function instead of a readonly property... DOH!
yes that will work. . .

but the convention for Name is a property. . .


I mean you dont execute

string s = myObj.Name();

do you?

usually it is

string s = myObj.Name;

just a matter of style
 
C#:
public interface myPlug
    {
        void Initialize(test.IHost host);
        string Name { get{} };
        void Go(object[] objs);
    }

joe i was not allowed to create a readonly property this way for Name.
there has to be a way to do it... arrrg

thanks
brandon
 
it wont' allow the semicolon... if i remove that, well it obviously doesn't work in my interface

... what's the deal?

thanks for the help
brandon
 
The proper code is as follows:

Code:
[b][size=2][color=#0000ff]public [/b][/color][/size][size=2][color=#ff0000]interface [/color][/size][size=2][color=#000000]myPlug[/color]
[/size][size=2][color=#006400]{

[/color][/size][size=2][color=#ff0000]void [/color][/size][b][size=2][color=#191970]Initialize[/b][/color][/size][size=2][color=#006400]([/color][/size][size=2][color=#000000]test[/color][/size][size=2][color=#006400].[/color][/size][size=2][color=#000000]IHost host[/color][/size][size=2][color=#006400]);

[/color][/size][size=2][color=#ff0000]string [/color][/size][size=2][color=#000000]Name [/color][/size][size=2][color=#006400]{[/color][/size][size=2][color=#8b4513]get[/color][/size][size=2][color=#006400];}

[/color][/size][size=2][color=#ff0000]void [/color][/size][b][size=2][color=#191970]Go[/b][/color][/size][size=2][color=#006400]([/color][/size][size=2][color=#ff0000]object[/color][/size][size=2][color=#006400][] [/color][/size][size=2][color=#000000]objs[/color][/size][size=2][color=#006400]);

}[/color][/size]

This is as reference from the MSDN documentation at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcrefTheInterfaceType.asp
 
Back
Top