Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

type converter in c#?

hello

i face a problem in trying to convert a value of textbox.text into an integer32

//order declaration

order.price=Convert.toInt32(textbox.text);

//compiler show me an error indicating format exception

the argument is in wrong format, and ensure i get right type

how to resolve that problem, thanks

4 Answers

Relevance
  • Pfo
    Lv 7
    10 years ago
    Favorite Answer

    You might want to use Integer.TryParse()

    It can handle bad input better.

    Usually if I have a text box that is strictly for numbers, I use the NumericUpDown control.

  • 4 years ago

    objective, Walmart, Radio Shack, or maybe maximum drug shops like CVS, Walgreens, and so on will carry effortless 50w converters/adapters. Walmart has a particularly finished set for $20. i'd be bowled over if perfect purchase did no longer have them.

  • 10 years ago

    Go thru this code....

    using System;

    using System.ComponentModel;

    using System.Globalization;

    using System.Drawing;

    public class PointConverter : TypeConverter {

    // Overrides the CanConvertFrom method of TypeConverter.

    // The ITypeDescriptorContext interface provides the context for the

    // conversion. Typically, this interface is used at design time to

    // provide information about the design-time container.

    public override bool CanConvertFrom(ITypeDescriptorContext context,

    Type sourceType) {

    if (sourceType == typeof(string)) {

    return true;

    }

    return base.CanConvertFrom(context, sourceType);

    }

    // Overrides the ConvertFrom method of TypeConverter.

    public override object ConvertFrom(ITypeDescriptorContext context,

    CultureInfo culture, object value) {

    if (value is string) {

    string[] v = ((string)value).Split(new char[] {','});

    return new Point(int.Parse(v[0]), int.Parse(v[1]));

    }

    return base.ConvertFrom(context, culture, value);

    }

    // Overrides the ConvertTo method of TypeConverter.

    public override object ConvertTo(ITypeDescriptorContext context,

    CultureInfo culture, object value, Type destinationType) {

    if (destinationType == typeof(string)) {

    return ((Point)value).X + "," + ((Point)value).Y;

    }

    return base.ConvertTo(context, culture, value, destinationType);

    }

    }

  • 10 years ago

    try using

    order.price=Int.Parse(textbox.text);

Still have questions? Get your answers by asking now.