On 29 Aug 2006 16:51:22 -0700,
ML****@hotmail. com wrote:
>I am passing multiple structures in a single function call. Some could
be valued while others are empty. Instead of spliting it into a million
functions to cover all the different possible combinations, I want to
keep it a single, simple function. Passing nullable parameters helps me
achieve it.
Mattias Sjögren wrote:
>I need to do this because I am going to
pass the pointer to an unmanaged DLL.
So why does the variable have to be nullable to begin with?
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
A nullable type (int?) is just C# syntactic sugar for a wrapper around
the Nullable<Tstruc ture, which is defined like this:
[Serializable, StructLayout(La youtKind.Sequen tial),
TypeDependency( "System.Collect ions.Generic.Nu llableComparer` 1"),
TypeDependency( "System.Collect ions.Generic.Nu llableEqualityC omparer`1")]
public struct Nullable<Twhere T: struct
{
private bool hasValue;
internal T value;
public Nullable(T value);
public bool HasValue { get; }
public T Value { get; }
public T GetValueOrDefau lt();
public T GetValueOrDefau lt(T defaultValue);
public override bool Equals(object other);
public override int GetHashCode();
public override string ToString();
public static implicit operator Nullable<T>(T value);
public static explicit operator T(Nullable<Tval ue);
}
So your interop code has to deal with the 2 fields, the hasValue flag
and the value, which obviously can be of different sizes.
--
Philip Daniels