Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 23, 2011 03:02 PM by MIB426
Contributor
3511 Points
852 Posts
Jun 23, 2011 11:22 AM|LINK
Dear All
I created FirstClass.py as below:
class Employee: FirstName = '' LastName = '' Age = 0
Then I created another file TestFirstClass.py as below:
import sys sys.path.append('C:\\WINDOWS\Microsoft.NET\\Framework\\v4.0.30319') import clr import System import System.Collections.Generic from FirstClass import Employee list = System.Collections.Generic.List[type(Employee)]() g1 = Employee g1.FirstName = 'A' g1.LastName = 'B' g1.Age = 35 list.Add(g1) g2 = Employee g2.FirstName = 'C' g2.LastName = 'D' g2.Age = 5 list.Add(g2) for s in list: print s.FirstName, s.Age
But the result it shows:
C 5C 5It should be
A 35C 5Does anyone know what is wrong??
Thank You
Jun 23, 2011 03:02 PM|LINK
I found the answer,
I should make type as class.
list = System.Collections.Generic.List[type( MyGreetings())]() g1 = MyGreetings() g1.FirstName = 'A' g1.LastName = 'B' g1.Age = 35 list.Add(g1) g2 = MyGreetings() g2.FirstName = 'C' g2.LastName = 'D' g2.Age = 5 list.Add(g2)
MIB426
Contributor
3511 Points
852 Posts
System.Collections.Generic Output Issue
Jun 23, 2011 11:22 AM|LINK
Dear All
I created FirstClass.py as below:
class Employee: FirstName = '' LastName = '' Age = 0Then I created another file TestFirstClass.py as below:
import sys sys.path.append('C:\\WINDOWS\Microsoft.NET\\Framework\\v4.0.30319') import clr import System import System.Collections.Generic from FirstClass import Employee list = System.Collections.Generic.List[type(Employee)]() g1 = Employee g1.FirstName = 'A' g1.LastName = 'B' g1.Age = 35 list.Add(g1) g2 = Employee g2.FirstName = 'C' g2.LastName = 'D' g2.Age = 5 list.Add(g2) for s in list: print s.FirstName, s.AgeBut the result it shows:
C 5
C 5
It should be
A 35
C 5
Does anyone know what is wrong??
.NET is only way to go
MCP, MCSE, MCDBA, MCSD, MCAD
MIB426
Contributor
3511 Points
852 Posts
Re: System.Collections.Generic Output Issue
Jun 23, 2011 03:02 PM|LINK
Dear All
I found the answer,
I should make type as class.
.NET is only way to go
MCP, MCSE, MCDBA, MCSD, MCAD