pawhan11 Posted July 16, 2018 Report Share Posted July 16, 2018 Hello, 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?? cast.vi Quote Link to comment
Rolf Kalbermatter Posted July 17, 2018 Report Share Posted July 17, 2018 (edited) 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 July 17, 2018 by rolfk Quote Link to comment
ak_nz Posted September 24, 2018 Report Share Posted September 24, 2018 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.