strongly typed ArrayList - possible?

Can I

Member
Joined
Oct 23, 2006
Messages
12
Location
Coventry, UK
Programming Experience
3-5
hello,

I want to make a data provider out of ArrayList containing Author class instances, and to do that I need that list to be strongly typed. Is there a way to achive it in VB.NET?
 
The standarway to create a strongly-typed collection is to inherit the CollectionBase class and then reproduce the members of the ArrayList but to accept and return only objects of a specific type. The CollectionBase class exists specifically for this purpose. It maintains an ArrayList internally but you basically filter the objects being added to allow only a specific type.
 
.net framework 2.x to be more acurate.
True I didn't look at the Can I's profile, but that's probably because I can't imagine why anyone would still be targeting the 1.x framework with new work.
Not everyone feels the need to pay for VS 2005 if they've already paid for VS.NET 2003 and it can do everything they need. Not everyone upgrades blindly to the newest thing if there isn't a compelling reason for them to do so. We'd all like a newer and better car but we don't all go out and buy one every time one's released.
 
.net framework 2.x to be more acurate.
True I didn't look at the Can I's profile, but that's probably because I can't imagine why anyone would still be targeting the 1.x framework with new work.
I'm doing .NET project on my uni and the lecturer is unfortunatelly a bit old fashioned

maybe if I find free hosting for project written in .NET2.0 he'll let me go with it, because uni has some older version istalled
 
I dont want to get into a deep philosophical debate about the need to stay up to date in this industry, but if the only argument against upgrading is financial, then the SDK is available from MS as a free download and you can get a free copy of VS2005 express or there is Sharpdevelop which is an excellent open source IDE
 
There are people still coding in VB6. There is no specific need to stay up-to-date. If I paid $1000 for VS.NET 2003 and it does all I need, I'm not going to start using VB Express or SharpDevelop to create production applications. I don't know if that's the case here but don't assume that everyone will be using the latest and greatest just because it's the latest and greatest. There are plenty of people still using older versions of VS and VB for plenty of valid reasons, not least of which is the fact that VS 2005 crashes way too much.
 
try this

public class mydatatableinfo

private m_pkid as integer = 0
private m_name as string = ""

sub new()
mybase.new
end sub

sub new(byval pkid as integer, byval name as string)
m_pkid = pkid
m_name = name
end sub

public property pkid as integer
get
return m_pkid
end get
set(byval value as integer)
m_pkid = value
end set
end property

public property name as string
get
return m_name
end get
set(byval value as string)
m_name = value
end set
end property
end class

man i hate typing properties ohh <serializable>public class must make it wire friendly

public class dblayer
public function dbgetdata as mydatatableinfo()
dim c as new arralylist
do something to get your data into a datareader, or any collection


using dr as datareader
while dr.read
dim x as new mydatatableinfo
x.pkid = IIF(IsDbNull(d("pkid")), 0, d("pkif"))
x.name = IIF(IsDbNell(d("name"), "', d("name")
c.add(x)
return ctype(gettype(c.toarray), mydatatableinfo,mydatatableinfo())
end function

end class
to implement this in your UI

private m_mydatatableinfo as mydatatableinfo
private m_mydatatableinfoList as mydatatableinfo()

private sub load
dim db as new dblayer
m_mydatatableinfoList = db.getdata
mycontrol.datasource = m_mydatatableinfoList

or

for each i as mydatatableinfo in m-mydatatableinfoList

next

or m-mydatatableinfo = new mydatatableinfo
m_mydatatableinfo = m_mydatatableinfoList.getvalue(0)

mytextbox.databinding.add('text",m_mydatatableinfo,"name")
 
Back
Top