dimanche 15 mai 2016

How to pass a common struct having one of it's fields take on multiple types

I would really appreciate help on this. I'm very new to C#. Referencing the code below. I need to fill a List with SearchReplace structs. The problem i'm not sure how to solve. I need the "ReplaceValue" field in the struct to also accept other types like integer or maybe an enum that I can use for downstream logic.

I definitely want to avoid boxing by making ReplaceValue type object.

public struct SearchReplace
{
    public SearchReplace(string data, string searchValue, string replaceValue)
    {
        this.Data = data;
        this.SearchValue = searchValue;
        this.ReplaceValue = replaceValue;
    }

    string Data;
    string SearchValue;
    string ReplaceValue;
}


public List<SearchReplace> edits;

Aucun commentaire:

Enregistrer un commentaire