Solved

convert long to string using as

Posted on 2014-10-13
8
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 34

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 34

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 34

Expert Comment

by:it_saige
ID: 40377861
Not a problem.

-saige-
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

710 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