473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Type conversion

I'm using a third party .NET 2 DLL from VB.NET and I'm am setting a property
of type 'int'. However, if I set a value larger than a 'short' (32k) then
reading the property back returns a negative number. Can someone tell me
what is likely to be happening within the property procedure that would
cause this? (The property should just be storing the value but appears to be
doing something unintentionally.)

I have a SQL stored proc that receives the negative value and, as a
temporary bug fix, I want to be able to reverse the procedure to get back to
the original number. I appreciate that a narrowing conversion has probably
occured so its possible that I can't get back to the original number.
Nov 13 '07 #1
1 1315
chris fellows <ch**********@nospam.co.ukwrote:
I'm using a third party .NET 2 DLL from VB.NET and I'm am setting a property
of type 'int'. However, if I set a value larger than a 'short' (32k) then
reading the property back returns a negative number. Can someone tell me
what is likely to be happening within the property procedure that would
cause this? (The property should just be storing the value but appears to be
doing something unintentionally.)
I suspect it's being converted to a short behind the scenes, whether
intentionally or not.
I have a SQL stored proc that receives the negative value and, as a
temporary bug fix, I want to be able to reverse the procedure to get back to
the original number. I appreciate that a narrowing conversion has probably
occured so its possible that I can't get back to the original number.
Well exactly. In C# you could cast from int to ushort, then back to int
again... for instance:

using System;

public class Test
{
static short dodgy;

public static int Dodgy
{
get { return dodgy; }
set { dodgy = (short) value; }
}

public static int SlightlyDodgy
{
get { return (ushort) Dodgy; }
set { Dodgy = value; }
}

public static void Main()
{
Dodgy = 60000;
Console.WriteLine (Dodgy);
Console.WriteLine (SlightlyDodgy);
}
}

However, that won't work for numbers over 65535. What happens when you
set the property to, say, 100000?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 13 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mark Oliver | last post by:
Hi, I want to put a type conversion in my class, but I don't want the conversion to be usable in a passed parameter because it makes no sense. class cData { string s; public cData(string s)...
7
by: Madhu Gopinathan | last post by:
Hi, I hope this is the right forum for this question. I am extending ICollection to create a Collection Type (say MyCollection) wherein I can control the types of objects being added to the...
27
by: Yuriy Solodkyy | last post by:
Hi VS 2005 beta 2 successfully compiles the following: using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program {
3
by: pgconnolly | last post by:
/* foreach does implicit type conversion on elements of a params argument or Generic.List. * This is not good. * Examples of evil follow... */ using System; // I love it when C# is strict...
16
by: Enekajmer | last post by:
Hi, 1 int main() 2 { 3 float a = 17.5; 4 printf("%d\n", a); 5 printf("%d\n", *(int *)&a); 6 return 0; 7 }
2
by: Martin v. Lwis | last post by:
I've been working on PEP 353 for some time now. Please comment, in particular if you are using 64-bit systems. Regards, Martin PEP: 353 Title: Using ssize_t as the index type Version:...
1
by: lovecreatesbeauty | last post by:
There is a warning/(error? I remember it is an error for line 10 on some compilers before. At least on g++, it is an error.) for line 10. I first read a similar example from `Expert C Programming...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
4
by: zaeminkr | last post by:
I got a good answer here I have still confusing part. I have two very simple classes class DRect { private : double x0, y0, x1, y1; public : DRect(double a, double b, double c, double d) :...
8
by: Smithers | last post by:
Are there any important differences between the following two ways to convert to a type?... where 'important differences' means something more profound than a simple syntax preference of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.