473,804 Members | 3,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

An easy question about GetType()

Hello!!

This first expression return System.Int32. The type that is returned is a
string. This is perfect understandable.
Console.WriteLi ne(7.GetType(). FullName);

In this second expression is the same returned System.Int32. The type that
is returned is System.RuntimeT ype
Console.WriteLi ne(7.GetType()) ;

Now to my question how can the System.Int32 be written when the type is
System.RuntimeT ype

//Tony
Oct 2 '07 #1
5 1461
No; 7.GetType() returns a Type instance, representing System.Int32.
There are different variants of Type, however, depending on the
scenario. In this case, Type instance (representing System.Int32)
happens to be a RuntimeType. However, it still *represents*
System.Int32.

Does that make sense? RuntimeType is the Type of the Type ;-p

If the question is about what gets written, then it is because
RuntimeType.ToS tring() has been overridden to return the name of the
represented type.

Marc
Oct 2 '07 #2
"TonyJ" <jo************ *****@telia.com wrote in message
news:Oo******** ******@TK2MSFTN GP06.phx.gbl...
[...]
In this second expression is the same returned System.Int32. The type that
is returned is System.RuntimeT ype
Console.WriteLi ne(7.GetType()) ;
Console.WritelL ine calls the ToString method on its Object argument, so
you are actually seeing 7.GetType().ToS tring(), which happens to return
"System.Runtime Type".
Now to my question how can the System.Int32 be written when the type is
System.RuntimeT ype
In your other example, Console.WriteLi ne(7.GetType(). FullName);, you are
invoking the property FullName on the result of GetType, which does not
return the same value as the method ToString of the same object.
Oct 2 '07 #3
Hello!!

You say that
"RuntimeType.To String() has been overridden to return the name of the
represented type."

I haven't overridden anything not even ToString(). What do you mean?

//Tony
"Marc Gravell" <ma**********@g mail.comskrev i meddelandet
news:Oh******** ******@TK2MSFTN GP05.phx.gbl...
No; 7.GetType() returns a Type instance, representing System.Int32.
There are different variants of Type, however, depending on the
scenario. In this case, Type instance (representing System.Int32)
happens to be a RuntimeType. However, it still *represents*
System.Int32.

Does that make sense? RuntimeType is the Type of the Type ;-p

If the question is about what gets written, then it is because
RuntimeType.ToS tring() has been overridden to return the name of the
represented type.

Marc


Oct 2 '07 #4
On Oct 2, 12:50 pm, "TonyJ" <johansson.ande rs...@telia.com wrote:
You say that
"RuntimeType.To String() has been overridden to return the name of the
represented type."

I haven't overridden anything not even ToString(). What do you mean?
The type "System.Runtime Type" has overridden ToString(). That
overridden method is what's being called when you write:

Console.WriteLi ne(7.GetType()) ;

I'm still not entirely clear what you're trying to do. Could you give
more description of what you're trying to achieve?

Jon

Oct 2 '07 #5
I haven't overridden anything not even ToString().
But then, you didn't write RuntimeType either...

Where are you even seeing RuntimeType? I've just tried:
Console.WriteLi ne(7.GetType()) ;
Console.WriteLi ne(7.GetType(). ToString());
Console.WriteLi ne(7.GetType(). FullName);

If you are using 1.1, then you're on your own - I burnt all my 1.1
tools a while ago ;-p
On 2.0 (which covers 3.0) and 3.5 it outputs System.Int32 three
times... I can only assume that you are looking in the IDE (immediate
window, or hover, etc) - in which case it will tell you about the
instance that is being queried, including it's Type (which in this
case *happens* to be a Type itself [specifically, RuntimeType], but
that is coincidence).

So where are you seeing "RuntimeTyp e"?

Marc
Oct 2 '07 #6

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

Similar topics

8
46053
by: ron | last post by:
Hi, I am currently using the base class GetType() in the following way and was woundering if there was a different way of looking at types and doing a comparison for equality. Thanks Ron foreach(System.Web.UI.Control ctl in this.Controls) {
0
935
by: Jax | last post by:
I'm having difficulty with creating dynamic types, TypeBuilder is attained through module builder which in turn comes from assembly builder. I assumed that if you save the assembly you'd save the type (made with the typebuilder) as well. When I save and load the assembly it comes back as having no types Is there a certain set of rules the type or assembly must comply to for it to be valid If so, what might those rules be In this example I...
2
4014
by: david.kao | last post by:
I have web service always return a string in Xml format, and I have the code at client side translates this return string into correct value. For example: my web service returns a <ret type=”System.int”>1</ret>. So my client logic will translate this into integer value of one by using Type.GetType() function. Likewise, if my web service returns a <ret type=”System.String”>abc</ret>, my client again translates this into string type....
6
19213
by: Jim Bancroft | last post by:
Hi everyone, I'm having some trouble with the code below. I receive a compile-time error on the second line saying "; expected": private static void myTestFunction(long myLong) { System.Data.SqlTypes.SqlInt32 myTestInt;
8
1587
by: Rachel Suddeth | last post by:
I'm trying to use reflection to create an object at runtime where the type is given by a string. I thought we should be able to do that, but so far it's not working. I'm trying to work on reproducing the scenario in a simpler way, but it's slow going, and maybe there is something very basic I don't know yet.... Given the following lines of code: ------------- CredLookup testLU = new CredLookup(); string sLUType =...
5
2271
by: Matthew | last post by:
I have a nice little Sub that saves data in a class "mySettings" to an XML file. I call it like so: Dim mySettings As mySettings = New mySettings mySettings.value1 = "someText" mySettings.value2 = "otherText" xmlSave("C:\folder\file.xml", mySettings) Here is the sub: Public Shared Sub xmlSave(ByVal path As String, ByVal config As
4
15111
by: Greg Burns | last post by:
What the difference between these two? System.Type.GetType("System.Int32") and GetType(Integer) Or more specifically, why does GetType(Integer) work, but not System.Type.GetType(Integer)? What namespace is the GetType function(?) part of?
3
4467
by: Joe Adams | last post by:
Hi All, How can I use GetType(<GenericType>).IsAssignableFrom(<MyType>) I need to now if the <MyType> is the same type of class as the <GenericType> without having to add the generic type member members. i.e. I do not want to use GetType(<GenericType>(Of String).IsAssignableFrom(<MyType>)
3
2806
by: b69316 | last post by:
Hi, I am a little confused on something. I am using DevC++. I am working on a project to make a "dinosaur walk across a map". I am not sure about the distance formula....i have no clue how to figure delta. I had it moving before I changed it to user input. any help would be greatly appreciated. I have included all my code
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9588
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.