Click to See Complete Forum and Search --> : [RESOLVED] Getting the alias of variable types
dee-u
Mar 8th, 2006, 11:57 PM
Is there an easy way to get the alias of variable types? To get string from System.String, etc...?
TIA
jmcilhinney
Mar 9th, 2006, 01:40 AM
I'm not sure what you mean. Are you talking about string, int, bool, etc.?
dee-u
Mar 9th, 2006, 03:39 AM
Yes, is there an automated way which I may be missing?
jmcilhinney
Mar 9th, 2006, 04:08 AM
An automated way to do what exactly? You just type them in the code window. Are you saying that you don't know what the intrinsic C# types are? There aren't too many and they're listed in a help topic entitled "Built-in Types Table", which also lists the corresponding .NET type.
jcis
Mar 9th, 2006, 01:43 PM
Or you want to get all that types automatically to use them inside your program? This is common when creating an IDE or if someone wants to add some sort of intelllisense to a editor.
jmcilhinney
Mar 9th, 2006, 03:52 PM
Or you want to get all that types automatically to use them inside your program? This is common when creating an IDE or if someone wants to add some sort of intelllisense to a editor.Hmmm... that sounds like a legitimate reason, but I doubt that there's a way to get them in code. The list of C# keywords is only 97 long, so hard-coding that into something like an editor would not be too difficult.
dee-u
Mar 9th, 2006, 10:02 PM
I've made a mapper (in the link in my sig) and when I am reading the DataTypes of table columns it is using System.String, System.DateTime, etc, I had to use a switch to be able to get their alias but I am hoping there is already a function/method to do such which I may be just missing...
jmcilhinney
Mar 9th, 2006, 10:12 PM
I've made a mapper (in the link in my sig) and when I am reading the DataTypes of table columns it is using System.String, System.DateTime, etc, I had to use a switch to be able to get their alias but I am hoping there is already a function/method to do such which I may be just missing...Why do you need to? It's the .NET type that's important I would think. A VB.NET Integer and a C# int are both implemented as a System.Int32, etc. What if the type is a date? There is no intrinsic date type in C# so you'd have to use DateTime, but in VB.NET you could use Date.
dee-u
Mar 9th, 2006, 10:45 PM
My brain maybe a little fuzzy, it just seem that I've read from somewhere that using the alias is better but I really can't recall where did I ran into this thought, or perhaps it's the other way around? When we use Set/Get properties is it just fine to use System.String instead of string only? I haven't seen any example that uses System.String in property get/set... :(
jcis
Mar 9th, 2006, 11:13 PM
In .NET (Vb.net/C#) variables has a GetType() property that brings the CTS type (The Common Type System). These are common type names inside .net framework (compatible between languages).
See this links
The Common Type System(CTS) benefits (http://www.dotnetspider.com/technology/kb/ShowSample.aspx?SampleId=367)
Data Types in C# (http://www.dotnetjunkies.com/Tutorial/3AD69E7D-202F-47DF-B41B-63FAED31ED23.dcik)
I think that's what you're talking about.
jmcilhinney
Mar 9th, 2006, 11:29 PM
It makes no difference whether you use the intrinsic data types of the current language or the .NET types in your code. The objects will still be implemented in exactly the same way and the MSIL will still be exactly the same. Intrinsic data types are a convenience when writing code but their use has no effect on the compiled assembly. You've used the term "alias" in your posts and that's exactly what they are: just another name for exactly the same thing. Like I said, all intrinsic data types are implemented using a .NET type.
dee-u
Mar 22nd, 2006, 07:41 PM
Sorry but I get it now, I was wrong in the first place, it was actually string against using String, etc... :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.