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<Tstructure, which is defined like this:
[Serializable, StructLayout(LayoutKind.Sequential),
TypeDependency("System.Collections.Generic.Nullabl eComparer`1"),
TypeDependency("System.Collections.Generic.Nullabl eEqualityComparer`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 GetValueOrDefault();
public T GetValueOrDefault(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<Tvalue);
}
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