我想开发一个包含字符串值的基本类,并且我想传递一个转换规则,该值应如何存储为 int 值。
当我没有完全错的时候,这应该可以使用某种委托。不幸的是,我不知道如何开始以及在互联网上搜索什么。
这里有一个简单的例子:
class MyClass
{
public string InputString { get; private set; }
public int OutputValue { get; set; }
public MyClass(string inputString)
{
this.InputString = inputString;
}
//I suspect that I need a method here taking some kind of delegate?
}
MyClass mC = new MyClass("abcd");
//here I now want to pass something to mC saying that each character should
// be transformed to its ascii value and be added to a total value
//or another object should transform abcd interpreting it hexadecimal