Using Net Data Types

When you work with .NET in IronPython, you have full access to every type that .NET supports. However, you don't always create these types as you would in another language. For example, when working with C# or Visual Basic, you simply declare a variable of a certain type and then make an assignment to it. When working in IronPython, you must remember that making an assignment creates a Python type, not a .NET type. For example, let's suppose you create a Ulnt32 variable and then make an assignment to it. Figure 7-10 shows the sequence of events that will occur.

As you can see, when you initially create the variable, IronPython recognizes it as a Ulnt32. In fact, even the type() function knows that this is a Ulnt32. When the code makes a simple assignment, however, notice that IronPython changes the type to a simple int. A check using type() shows that the data type has indeed changed. In order to change the value of a Ulnt32, you must make another assignment using the Ulnt32() constructor.

Rnv Iron Python Console

ad

>>> import System

a

»> !1yUar = System.UJnt32(S>

ZZj

»> MyUür

0 0

Post a comment

  • Receive news updates via email from this site