Solved

convert long to string using as

Posted on 2014-10-13
8
290 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

789 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