PC Review


Reply
Thread Tools Rate Thread

Beginning C#

 
 
Michael D. Ober
Guest
Posts: n/a
 
      21st Jul 2006
I am attempting to learn C# and have run into a fundamental type casting
problem for input strings. After reviewing the VS 2005 documentation, I am
obviously missing simple type conversion operators - specifically, string
(textbox input values) to numbers of various types. In C++ this would be
done with sscanf and in both VB6 and VB 2005 this would be done with either
C<type> (CDbl, CLng, etc.) or with the generic VB 2005 CType(textbox1.text,
Long).

My question is two fold - first what are the direct equivalents to the CDbl
and CLng series of VB functions and secondly, what is the general type
caster replacement for CType?

Thanks,
Mike Ober.



 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      21st Jul 2006
Michael,

In all of the methods that you have mentioned, the string was not cast
to the type that you wanted. Rather, those are functions that perform a
conversion.

These functions exist in .NET as well. They are static methods on the
Convert class, such as ToInt32, ToInt64, etc, etc.

They are available to all languages in .NET as well, since they are part
of the framework.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
news:nlWvg.2557$(E-Mail Removed)...
>I am attempting to learn C# and have run into a fundamental type casting
> problem for input strings. After reviewing the VS 2005 documentation, I
> am
> obviously missing simple type conversion operators - specifically, string
> (textbox input values) to numbers of various types. In C++ this would be
> done with sscanf and in both VB6 and VB 2005 this would be done with
> either
> C<type> (CDbl, CLng, etc.) or with the generic VB 2005
> CType(textbox1.text,
> Long).
>
> My question is two fold - first what are the direct equivalents to the
> CDbl
> and CLng series of VB functions and secondly, what is the general type
> caster replacement for CType?
>
> Thanks,
> Mike Ober.
>
>
>



 
Reply With Quote
 
Omatase@gmail.com
Guest
Posts: n/a
 
      21st Jul 2006
I don't know that there are direct replacements.

The best tools for casting in C# that I have found are in
System.Convert.

For instance:

System.Convert.ToInt32("3");

casting like:

object myObject = (int)15;

for the sake of argument, works as well (let's ignore for the moment
that it's something you would likely never do)

 
Reply With Quote
 
Michael D. Ober
Guest
Posts: n/a
 
      21st Jul 2006
Thanks - VB 2005 doesn't require this class, though I suspect it converts
the VB conversion functions into calls into the Convert class.

Mike.

"Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Michael,
>
> In all of the methods that you have mentioned, the string was not cast
> to the type that you wanted. Rather, those are functions that perform a
> conversion.
>
> These functions exist in .NET as well. They are static methods on the
> Convert class, such as ToInt32, ToInt64, etc, etc.
>
> They are available to all languages in .NET as well, since they are

part
> of the framework.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - (E-Mail Removed)
>
> "Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
> news:nlWvg.2557$(E-Mail Removed)...
> >I am attempting to learn C# and have run into a fundamental type casting
> > problem for input strings. After reviewing the VS 2005 documentation, I
> > am
> > obviously missing simple type conversion operators - specifically,

string
> > (textbox input values) to numbers of various types. In C++ this would

be
> > done with sscanf and in both VB6 and VB 2005 this would be done with
> > either
> > C<type> (CDbl, CLng, etc.) or with the generic VB 2005
> > CType(textbox1.text,
> > Long).
> >
> > My question is two fold - first what are the direct equivalents to the
> > CDbl
> > and CLng series of VB functions and secondly, what is the general type
> > caster replacement for CType?
> >
> > Thanks,
> > Mike Ober.
> >
> >
> >

>
>
>




 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this the beginning of the end clm_jr Windows XP Performance 3 30th Apr 2010 03:41 PM
Just beginning ! awsmitty Microsoft Access Getting Started 2 1st Nov 2009 02:25 AM
beginning vinnie Microsoft C# .NET 1 21st Aug 2007 07:44 AM
symbols in the beginning of the line and at the beginning of theline in style news.microsoft.com Microsoft Word New Users 3 11th Apr 2007 12:12 PM
Beginning C# Andy Microsoft C# .NET 2 9th Jan 2006 10:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:08 AM.