Error 1 The modifier 'abstract' is not valid for this item
-
I'm trying to build my C# project, I get the error: The modifier 'abstract' is not valid for this item Is the item: FieldChanged; In the following Interface:
namespace program.Drawing.Fields
{
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;public interface IFieldHolder {
abstract event FieldChangedEventHandler FieldChanged;
void AddField(Field field);
Field GetField(FieldType fieldType);
List GetFields();
bool HasField(FieldType fieldType);
void RemoveField(Field field);
void SetFieldValue(FieldType fieldType, object value);
}
} -
I'm trying to build my C# project, I get the error: The modifier 'abstract' is not valid for this item Is the item: FieldChanged; In the following Interface:
namespace program.Drawing.Fields
{
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;public interface IFieldHolder {
abstract event FieldChangedEventHandler FieldChanged;
void AddField(Field field);
Field GetField(FieldType fieldType);
List GetFields();
bool HasField(FieldType fieldType);
void RemoveField(Field field);
void SetFieldValue(FieldType fieldType, object value);
}
}Have a read at the link below
Quote:
•Abstract method declarations are only permitted in abstract classes.
Quote:
Interfaces and interface members are abstract;
http://msdn.microsoft.com/en-us/library/sf985hc5(v=vs.71).aspx[^] and here http://msdn.microsoft.com/en-us/library/ms173156.aspx[^]
-
Have a read at the link below
Quote:
•Abstract method declarations are only permitted in abstract classes.
Quote:
Interfaces and interface members are abstract;
http://msdn.microsoft.com/en-us/library/sf985hc5(v=vs.71).aspx[^] and here http://msdn.microsoft.com/en-us/library/ms173156.aspx[^]
-
You just need to remove the abstract declaration for the event.
namespace program.Drawing.Fields
{
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;public interface IFieldHolder { event FieldChangedEventHandler FieldChanged; void AddField(Field field); Field GetField(FieldType fieldType); List<Field> GetFields(); bool HasField(FieldType fieldType); void RemoveField(Field field); void SetFieldValue(FieldType fieldType, object value); }
}
-
I'm trying to build my C# project, I get the error: The modifier 'abstract' is not valid for this item Is the item: FieldChanged; In the following Interface:
namespace program.Drawing.Fields
{
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;public interface IFieldHolder {
abstract event FieldChangedEventHandler FieldChanged;
void AddField(Field field);
Field GetField(FieldType fieldType);
List GetFields();
bool HasField(FieldType fieldType);
void RemoveField(Field field);
void SetFieldValue(FieldType fieldType, object value);
}
}Just to expand slightly on the (correct) fix already posted: You can't put 'public' or 'abstract' on interface members, because by definition they are already public and abstract, so to prevent confusion* no access modifiers are permitted. *: or that's what the rationale is, anyway. I think it's silly, it prevents future expansion and the fact that the default scope (public abstract) in an interface is different from that (private) in a class is more confusing than making you write 'public abstract' on things in interfaces.
-
Just to expand slightly on the (correct) fix already posted: You can't put 'public' or 'abstract' on interface members, because by definition they are already public and abstract, so to prevent confusion* no access modifiers are permitted. *: or that's what the rationale is, anyway. I think it's silly, it prevents future expansion and the fact that the default scope (public abstract) in an interface is different from that (private) in a class is more confusing than making you write 'public abstract' on things in interfaces.
I think it makes sense that everything in an Interface is public and abstract by definition, but I don't like default modifiers on class members.
-
I think it makes sense that everything in an Interface is public and abstract by definition, but I don't like default modifiers on class members.
:thumbsup:
Luc Pattyn [My Articles] Nil Volentibus Arduum