CLS Compliant

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The msdn and all other books saying that the Unsigned integer(ex: UInt32) type is not CLSCompliant. But C# and VB.NET both are taking UInt32 as CLSCompliant. The following sample code compiles with out any errors by using either C# or VB.NET:

using System;
[assembly: CLSCompliant(true)]

namespace sample{
class sampCls{
static void Main(){
Console.Write(XYZ());
}

public UInt32 XYZ(){
return 0;
}
}
}
 
Well, I sure can't get something like that to compile in VB.Net. Here are my
equivalents of your XYZ function:

Public Function xyz() As UInt32
Return 0
End Function

or

Public Function xyz() As UInt32
Return CType(0, System.UInt32)
End Function

and what I got as an error in both cases was:

Value of type 'Integer' cannot be converted to 'System.UInt32'.

So I'd like to know what your VB code was.

Regards,
Tom Dacon
Dacon Software Consulting


infoNsoft said:
The msdn and all other books saying that the Unsigned integer(ex: UInt32)
type is not CLSCompliant. But C# and VB.NET both are taking UInt32 as
CLSCompliant. The following sample code compiles with out any errors by
using either C# or VB.NET:
using System;
[assembly: CLSCompliant(true)]

namespace sample{
class sampCls{
static void Main(){
Console.Write(XYZ());
}

public UInt32 XYZ(){
return 0;
}
}
}
 
infoNsoft said:
The msdn and all other books saying that the Unsigned integer(ex: UInt32)
type is not CLSCompliant. But C# and VB.NET both are taking UInt32 as
CLSCompliant. The following sample code compiles with out any errors by
using either C# or VB.NET:

using System;
[assembly: CLSCompliant(true)]

namespace sample{
class sampCls{
static void Main(){
Console.Write(XYZ());
}

public UInt32 XYZ(){
return 0;
}
}
}

Well, given this code, there are no CLS violations. The type UInt32 is not
CLS compliant, but CLS compliance only applies to publically exposed
methods. A class without an access specifier is implicitly internal and
unrelated to the classes external interface and the CLS rules associated
with it.
Change your code to: public sampCls and you should get your error.
 
Back
Top