Compare Any Data-Type in C#

Hi,

is it possible to compare two variables of data type [i]Any[/i] without casting. Like

[code]
[FunctionBlock]
public class Test
{   
\t[Input, DataType("ANY_NUM")]
\tpublic Any Value1;
\t
\t[Input, DataType("ANY_NUM")]
\tpublic Any Value2;

\t[Output]
\tpublic bool Identical;

\t[Initialization]
\tpublic void __Init()
\t{
\t\tIdentical = false;              
\t}

\t[Execution]
\tpublic void __Process()
\t{
\t\tif (Value1.pRuntimeTypeHandle == Value2.pRuntimeTypeHandle)
\t\t\tIdentical = Value1 == Value2;
\t}
}
[/code]

The value of the Any variables is referenced (in your example) by the Value1.pValue and Value2.pValue fields. These are pointers to void - void* - so it is impossible to compare the contents of the referenced memory locations without knowing the type, because without the type you don’t know how many bytes to compare. If you knew the exact number of bytes being pointed to, I suppose you could use pointer arithmetic to compare each of the byte values, but in that case you probably know the type and could cast the value anyway.

Many thanks,

is the number of bytes not beeing represented by [b]nLength [/b]?

Ooh, good point. That may be the case, so you could try running a loop over each byte, starting at pValue, and compare the contents.