I have a class with a field that is assigned an array of type T or a dll object of type T that has an overload this [int i]to simulate an array (it uses unmanaged memory and accesses it using overload)
public T this[int i]
{
get
{
return ((T[])array)[i];
}
set { }
}
when I use the dll object, it throws an exception exception. I suggested that it (T[])would cause the []object to be overloaded , not casting on float[], but it always adds to float[], but the type of object FloatArrthat has public float this[int i].
Is there a way to treat primitive arrays as casts, treating other custom types as an overload trigger?
If this is not possible, how to return the type T, while a returned type, such as float, can be assembled from a simple float array or some non-standard type with overloading to return a float? I do not want to add float, int, byte, double, char, ... one by one. I need the type to Twork for everyone, is the object field an C # array or a custom type with an overloaded index?
What I really need:
public object array { get; set; }
public T this[int i]
{
get
{
return array[i];
}
set { }
}
Edit: if this is a bad design, please tell me. I need this class to consider a property, be it a C # array or a C ++ shell Cll object with overload [].
Edit-2: Here is what I used in my mind:
MyArr<float> gpu = new MyArr<float>(1024);
gpu.array=new float[1024];
gpu[35]=40;
or
MyArr<float> gpu = new MyArr<float>(1024);
gpu.allocateUnManagedToArray();
gpu[35]=40;
Edit-3: here is the custom class that I put in the array field:
public class FloatArr
{
public float this[int i]
{
get
{
unsafe
{
float* p = (float*)hArr.ToPointer();
return *(p + i);
}
}
set {
unsafe
{
float* p = (float*)hArr.ToPointer();
*(p + i) = value;
}
}
}
}
-4: :
[]- , ,
[]! - , #, , ++.
[] ( float ++ []).
, float int byte , . , , - , . struct, , .