Here's mine. Two assumptions:
1) Fixed length array.
2) Object must override the Equals method
class MyFireArray<T>
{
private T[] _data;
private bool _isAllSame;
// Array, assuming fixed size
public MyFireArray( int size )
{
_data = new T[ size ];
}
public void SetValueAll( T newval )
{
_data[0] = newval;
_isAllSame = true;
}
// Slightly tricky...
public void SetValue( int index, T newval )
{
if( _isAllSame && _data[ 0 ].Equals( newval ) )
{
// do nothing
}
else
{
_data[ index ] = newval;
_isAllSame = false;
}
}
// Assuming null is one of the acceptable value
public T GetValue( int index )
{
if( _isAllSame )
{
return _data[ 0 ];
}
else
{
return _data[ index ];
}
}
}
- Self control is the appetence of the most strongest man -