This is a hypothetical method that allows arrays to use functions a single object can use. This would allow arrays to use methods that are only available to a single object. I just need a generic method that runs on all types of arrays. This method will run another method on the individual values of that array. Then those individual values will be returned as an array.This would work with all types. This method, if possible, should not have any constraints to which objects can use it. Repeat, there is no constraint any where in the code. Is this possible in another form? Is this legal in C#?
string[] s = new string[] { "hi", "hello", "what's up" }
static void Main(string[] args)
{
string[] newS = s.ArrayTo(() => string.Remove(0,1));
foreach(string str in newS)
Console.WriteLine(str);
}
static class Ext
{
static T[] ArrayTo<T>(this T[] t,Action a)
{
List<T> ret = new List<T>();
foreach(T tOb in t)
{
ret.Add(
//t.a()); This line doesn't work
}
return ret.ToArray();
}
}
Output: i , ello , hat's up