C# Error: interface members cannot have definition -


I'm new to C #, and I do not know why I can not do this. One can provide a link or example that will get the same result.

  Public Interfaces IEffectEditorControl {object [] EffectParameterValues ​​{get; Set {isDirty = true; }} Bool isirty (mill); Set; } {IE; Set; }}  

Your compiler is correct, interface Can not have a definition in

defines contract for a class, that is, a list of properties and methods that should be implemented by the class in your example isDirty = true; The statement can not contain the actual code.

In other words, you should change it in:

  // It only lists all the members who have to implement a class, // if they If you want to implement the interface and pass the compile the public interface, then IEffectEditorControl {object [] EffectParameterValues ​​{get; Set; } // & lt; - statement was removed from Isdirty {get; Set; } {IE; Set; }}  

and then there is a definite class implementation by providing the required code:

  / / Anyone who accepts code interface IEffectEditorControl, // can now accept this concrete implementation (and you can get multiple sections // implementing the same interface) Public Class EffectEditorControl: IEffectEditorControl {private object [ ] _effectParameterValues; Public Object [] AffafPameter Value {Get; } Set {_effectParameterValues ​​= value; IsDirty = true; }} Public Balls Eyes {Get; Set; } Public IEffect TargetEffect {get; Set; In addition, note the difference between  EffectParameterValues ​​, which is a fully developed property with a backing field ( _effectParameterValues ​​), and  IsDirty < / Code> /  TargetEffect , which is with a private anonymous backing field. By setting  EffectParameterValues ​​, the entire setter block will be executed, both the backing field and  IsDirty  will modify the property. 

When you set your receives / entrants to specify a single value (such as IsDirty set in this example), you must add the actual backing field and manually Otherwise, you can use the simplest form.

Extension methods can sometimes do the same thing.

Alternatively, if you actually have a general functionality for the interface, then you can use an extension method. Note that it still does not add the actual code to an interface, but essentially creates static methods that can easily be applied to each class implementing that interface.

In this case, you "dumb" and apply it to everything automatically:

  // setting the effect parameter value directly // not set the ESDIIR flag in this set Public Effectifier Controller: IFFE Editor Control [Public Object] Effampamulator Values ​​{get; Set; } Public bool IsDirty {Get; Set; } Public IEffect TargetEffect {get; Set; }}  

... then add an extension method to the interface:

  public static class IEffectEditorControlExtension {public static zero setpermatorsand markAdsDesha (this IEffectEditorControl obj, Object [] value) {obj.EffectParameterValues ​​= value; Obj.IsDirty = true; }}  

... and then later remember to assign the parameter to that method:

  // This is the static method above the editor Will call .set parameter and MarkAdsDisha (parameters);  

This is likely to not be the best use for expansion methods (anything prevents you from setting the EffectParameter Values ​​ directly and messing up the whole thing ), But I've added it to perfection.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -