Solved

convert long to string using as

Posted on 2014-10-13
8
288 Views
Last Modified: 2014-10-13
I am trying to convert a long value to a string - I keep getting the error "the as operator must be used with a reference type" how do I fix this

int number;
                    int thiscontroller = int.TryParse(myBus.Controller_EEProm[EEPROM.CONTROLLER.SerialNum].Data as long,number);

Open in new window

0
Comment
Question by:r3nder
  • 5
  • 3
8 Comments
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 40377726
Which is correct.  A long is not a reference type, it is a value type.  You have to use:
int number;
bool thiscontroller = int.TryParse((long)(myBus.Controller_EEProm[EEPROM.CONTROLLER.SerialNum].Data), out number);

Open in new window


More on value types vs. reference types:

http://www.albahari.com/valuevsreftypes.aspx

More on the as Keyword:

http://msdn.microsoft.com/en-us/library/cscsdfbt.aspx

-saige-
0
 
LVL 6

Author Comment

by:r3nder
ID: 40377748
sorry there is an error cannot convert 'bus.busbuffer' to long
if I specify  it as long I get 1095
0
 
LVL 6

Author Comment

by:r3nder
ID: 40377753
I am trying to convert myBus.Controller_EEProm[EEPROM.CONTROLLER.SerialNum].Data as long this gives me 1095
myBus.Controller_EEProm[EEPROM.CONTROLLER.SerialNum].Data gives me 'mybus.busBuffer'
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 33

Expert Comment

by:it_saige
ID: 40377754
What is the datatype of bus.busbuffer?  *Most likely it is a byte array.*

-saige-
0
 
LVL 6

Author Comment

by:r3nder
ID: 40377808
it is a struct
public struct BusBuffer
        {
            public float asfloat;
            public uint asLong;
            public int assignedLong;
            public short assignedshort0;
            public short assignedshort1;
            public ushort asunsignedshort0;
            public ushort asunsignedshort1;
            public byte Byte0;
            public byte Byte1;
            public byte Byte2;
            public byte Byte3;
0
 
LVL 6

Author Comment

by:r3nder
ID: 40377843
I feel like an idiot - not as long it is a name aslong - thnks anyway it
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40377848
Thanks it - sorry for the inconvinience
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40377861
Not a problem.

-saige-
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question