Solved

convert long to string using as

Posted on 2014-10-13
8
279 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 32

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
 
LVL 32

Expert Comment

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

-saige-
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 32

Expert Comment

by:it_saige
ID: 40377861
Not a problem.

-saige-
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now