Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

convert long to string using as

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
r3nder
Asked:
r3nder
  • 5
  • 3
1 Solution
 
it_saigeDeveloperCommented:
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
 
r3nderAuthor Commented:
sorry there is an error cannot convert 'bus.busbuffer' to long
if I specify  it as long I get 1095
0
 
r3nderAuthor Commented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
it_saigeDeveloperCommented:
What is the datatype of bus.busbuffer?  *Most likely it is a byte array.*

-saige-
0
 
r3nderAuthor Commented:
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
 
r3nderAuthor Commented:
I feel like an idiot - not as long it is a name aslong - thnks anyway it
0
 
r3nderAuthor Commented:
Thanks it - sorry for the inconvinience
0
 
it_saigeDeveloperCommented:
Not a problem.

-saige-
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now