Jump to content

.NET type conversions in LabVIEW

Recommended Posts


I need to implement this simple data casting of c# objects in LV


    object o = "MyString";
    SqlString t1 = o as String      


How this can be done in LV??





Share this post

Link to post
Share on other sites

You can't do that! Your LabVIEW code really is equivalent to this .Net code which will definitely throw an error!

int stringdata[] = {1, 2};
String string = new String(stringdata);
SqlString sql = (SqlString)string;       // throwing an error

and String is not an SqlString in a long shot and neither is an SqlString a String, as it does not inherit from String at all. It is its own object type.

Maybe .Net does some super magic behind the scenes and the C# code you wrote is valid but purely from a type compatible point of view reinterpreting the String object o as SqlString isn't a direct compatible conversion.

The proper code construct would be something along the lines of:

SqlString sql = new SqlString(o);

In LabVIEW use the SqlString contstructor that allows to pass in a String paremeter for the initialization.

Edited by rolfk

Share this post

Link to post
Share on other sites

Just a note that the C# code shown by the OP isn't magically interpreted differently by the C# compiler and will throw an exception at run-time just as rolfk says and for the reason he says.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.