By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,734 Members | 890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,734 IT Pros & Developers. It's quick & easy.

Best Method

P: n/a
I am looking for a way to store maybe in an array or dictionary... two
fields....
first field would be a string... second would be a date...
for example.. if i called up myinfo(0) it would show "the first Day"
"1/1/2008" ???
Brian
Jun 27 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Brian,

What do you want to do store data or put data in a class.

For two values the latter is in my idea without sense, and for that are 100
best methods.

The same is for store this kind of data, there are probably 20 best methods.

One of those maybe this one.

http://msdn.microsoft.com/en-us/library/3ak841sy.aspx

Cor
"Brian" <bs********@community.nospamschreef in bericht
news:un**************@TK2MSFTNGP05.phx.gbl...
>I am looking for a way to store maybe in an array or dictionary... two
fields....
first field would be a string... second would be a date...
for example.. if i called up myinfo(0) it would show "the first Day"
"1/1/2008" ???
Brian

Jun 27 '08 #2

P: n/a
On May 14, 9:26 pm, "Brian" <bsgalla...@community.nospamwrote:
I am looking for a way to store maybe in an array or dictionary... two
fields....
first field would be a string... second would be a date...
for example.. if i called up myinfo(0) it would show "the first Day"
"1/1/2008" ???
Brian
Sounds to me you just need to make a custom class that has two
properties, label and date:

//////////////
Public Class YourClassNameHere

Private _Label As String = String.Empty
Private _TheDate As DateTime = DateTime.Now

Public Sub New()

End Sub

Public Sub New(ByVal label As String, ByVal theDate As DateTime)
Me.New()

Me.Label = label
Me.TheDate = TheDate
End Sub

Public Property Label As String
Get
Return _Label
End Get
Set (ByVal value As String)
_Label = value
End Set
End Property

Public Property TheDate As DateTime
Get
Return _TheDate
End Get
Set (ByVal value As DateTime)
_TheDate = value
End Set
End Property

'// I typed this in the message so this statement might
'// not be formatted correctly
Public Overrides Function ToString() As String
Return String.Format("{0} {1}", Me.Label, Me.TheDate)
End Function

End Class
//////////////

Then you could just store these objects in any sort of IEnumerable
field (array, list, arraylist, etc) and then when you pull them out of
the array (or whatever) and call the .ToString() method, you will get
the string like you requested.

Thanks,

Seth Rowe [MVP]
Jun 27 '08 #3

P: n/a
Simple and best approach for implementing this in .Net Framework 2.0 is to
create collection of Type Generic and define the Type of the value that you
will persist. This will solve majority of the problems. Also this is good in
terms of performance.

Thanks,
Mayur H Chauhan
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:fa**********************************@m45g2000 hsb.googlegroups.com...
On May 14, 9:26 pm, "Brian" <bsgalla...@community.nospamwrote:
>I am looking for a way to store maybe in an array or dictionary... two
fields....
first field would be a string... second would be a date...
for example.. if i called up myinfo(0) it would show "the first Day"
"1/1/2008" ???
Brian

Sounds to me you just need to make a custom class that has two
properties, label and date:

//////////////
Public Class YourClassNameHere

Private _Label As String = String.Empty
Private _TheDate As DateTime = DateTime.Now

Public Sub New()

End Sub

Public Sub New(ByVal label As String, ByVal theDate As DateTime)
Me.New()

Me.Label = label
Me.TheDate = TheDate
End Sub

Public Property Label As String
Get
Return _Label
End Get
Set (ByVal value As String)
_Label = value
End Set
End Property

Public Property TheDate As DateTime
Get
Return _TheDate
End Get
Set (ByVal value As DateTime)
_TheDate = value
End Set
End Property

'// I typed this in the message so this statement might
'// not be formatted correctly
Public Overrides Function ToString() As String
Return String.Format("{0} {1}", Me.Label, Me.TheDate)
End Function

End Class
//////////////

Then you could just store these objects in any sort of IEnumerable
field (array, list, arraylist, etc) and then when you pull them out of
the array (or whatever) and call the .ToString() method, you will get
the string like you requested.

Thanks,

Seth Rowe [MVP]

Jun 27 '08 #4

P: n/a
Hi Seth,

Is this not more simple as it has to be in an array.

Dim myArray() as String = {"The first Day", "1/1/2008"}

I could not make more from the question of the OP.

:-)

Cor

"rowe_newsgroups" <ro********@yahoo.comschreef in bericht
news:fa**********************************@m45g2000 hsb.googlegroups.com...
On May 14, 9:26 pm, "Brian" <bsgalla...@community.nospamwrote:
>I am looking for a way to store maybe in an array or dictionary... two
fields....
first field would be a string... second would be a date...
for example.. if i called up myinfo(0) it would show "the first Day"
"1/1/2008" ???
Brian

Sounds to me you just need to make a custom class that has two
properties, label and date:

//////////////
Public Class YourClassNameHere

Private _Label As String = String.Empty
Private _TheDate As DateTime = DateTime.Now

Public Sub New()

End Sub

Public Sub New(ByVal label As String, ByVal theDate As DateTime)
Me.New()

Me.Label = label
Me.TheDate = TheDate
End Sub

Public Property Label As String
Get
Return _Label
End Get
Set (ByVal value As String)
_Label = value
End Set
End Property

Public Property TheDate As DateTime
Get
Return _TheDate
End Get
Set (ByVal value As DateTime)
_TheDate = value
End Set
End Property

'// I typed this in the message so this statement might
'// not be formatted correctly
Public Overrides Function ToString() As String
Return String.Format("{0} {1}", Me.Label, Me.TheDate)
End Function

End Class
//////////////

Then you could just store these objects in any sort of IEnumerable
field (array, list, arraylist, etc) and then when you pull them out of
the array (or whatever) and call the .ToString() method, you will get
the string like you requested.

Thanks,

Seth Rowe [MVP]
Jun 27 '08 #5

P: n/a
On May 15, 12:00 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
Hi Seth,

Is this not more simple as it has to be in an array.

Dim myArray() as String = {"The first Day", "1/1/2008"}

I could not make more from the question of the OP.

:-)

Cor

"rowe_newsgroups" <rowe_em...@yahoo.comschreef in berichtnews:fa**********************************@m 45g2000hsb.googlegroups.com...
On May 14, 9:26 pm, "Brian" <bsgalla...@community.nospamwrote:
I am looking for a way to store maybe in an array or dictionary... two
fields....
first field would be a string... second would be a date...
for example.. if i called up myinfo(0) it would show "the first Day"
"1/1/2008" ???
Brian
Sounds to me you just need to make a custom class that has two
properties, label and date:
//////////////
Public Class YourClassNameHere
Private _Label As String = String.Empty
Private _TheDate As DateTime = DateTime.Now
Public Sub New()
End Sub
Public Sub New(ByVal label As String, ByVal theDate As DateTime)
Me.New()
Me.Label = label
Me.TheDate = TheDate
End Sub
Public Property Label As String
Get
Return _Label
End Get
Set (ByVal value As String)
_Label = value
End Set
End Property
Public Property TheDate As DateTime
Get
Return _TheDate
End Get
Set (ByVal value As DateTime)
_TheDate = value
End Set
End Property
'// I typed this in the message so this statement might
'// not be formatted correctly
Public Overrides Function ToString() As String
Return String.Format("{0} {1}", Me.Label, Me.TheDate)
End Function
End Class
//////////////
Then you could just store these objects in any sort of IEnumerable
field (array, list, arraylist, etc) and then when you pull them out of
the array (or whatever) and call the .ToString() method, you will get
the string like you requested.
Thanks,
Seth Rowe [MVP]
The twist I saw was that he wanted to display both the label and the
date together, hence my ToString() override. Though you are correct,
the question was a bit vague to give an accurate answer.

Thanks,

Seth Rowe [MVP]
Jun 27 '08 #6

P: n/a
ok,, let me try to tell say it different way what I am wanting to do.
I want to have a collection of dates to add to the monthcalendar.boldeddates
but, I would like to list the dates I have bolded in something like a text
box.... and show that
1/1/2008 is New Years day... "New Years Day 1/1/2008"
and I'll have a list of holidays for collection...

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:ba**********************************@c58g2000 hsc.googlegroups.com...
On May 15, 12:00 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
>Hi Seth,

Is this not more simple as it has to be in an array.

Dim myArray() as String = {"The first Day", "1/1/2008"}

I could not make more from the question of the OP.

:-)

Cor

"rowe_newsgroups" <rowe_em...@yahoo.comschreef in
berichtnews:fa**********************************@ m45g2000hsb.googlegroups.com...
On May 14, 9:26 pm, "Brian" <bsgalla...@community.nospamwrote:
I am looking for a way to store maybe in an array or dictionary...
two
fields....
first field would be a string... second would be a date...
for example.. if i called up myinfo(0) it would show "the first Day"
"1/1/2008" ???
Brian
Sounds to me you just need to make a custom class that has two
properties, label and date:
//////////////
Public Class YourClassNameHere
Private _Label As String = String.Empty
Private _TheDate As DateTime = DateTime.Now
Public Sub New()
End Sub
Public Sub New(ByVal label As String, ByVal theDate As DateTime)
Me.New()
Me.Label = label
Me.TheDate = TheDate
End Sub
Public Property Label As String
Get
Return _Label
End Get
Set (ByVal value As String)
_Label = value
End Set
End Property
Public Property TheDate As DateTime
Get
Return _TheDate
End Get
Set (ByVal value As DateTime)
_TheDate = value
End Set
End Property
'// I typed this in the message so this statement might
'// not be formatted correctly
Public Overrides Function ToString() As String
Return String.Format("{0} {1}", Me.Label, Me.TheDate)
End Function
End Class
//////////////
Then you could just store these objects in any sort of IEnumerable
field (array, list, arraylist, etc) and then when you pull them out of
the array (or whatever) and call the .ToString() method, you will get
the string like you requested.
Thanks,
Seth Rowe [MVP]

The twist I saw was that he wanted to display both the label and the
date together, hence my ToString() override. Though you are correct,
the question was a bit vague to give an accurate answer.

Thanks,

Seth Rowe [MVP]

Jun 27 '08 #7

P: n/a
The shortest way I now with one row

\\\\
dim dt as new datatable
dim dcfirstcolumn as new datacolumn("first")
dim dcsecondcolumn as new datacolumn("second")
dt.colums.add(dcfirstcolumn)
dt.colums.add(dcsecondcolumn)
dim dr as new datarow = dt.rows.newrow
dr(dcfirstcolumn) = "The first Day"
dr(dcsecondcolumn) = "1/2/2008"
dt.rows.add(dr)
myListBox.DataSource = dt
myListBox.DisplayMember = "first"
myListbox.ValueMember = "second"
///

Typed in this message so watch errors.

Cor

"Brian" <bs********@community.nospamschreef in bericht
news:uK**************@TK2MSFTNGP03.phx.gbl...
ok,, let me try to tell say it different way what I am wanting to do.
I want to have a collection of dates to add to the
monthcalendar.boldeddates
but, I would like to list the dates I have bolded in something like a text
box.... and show that
1/1/2008 is New Years day... "New Years Day 1/1/2008"
and I'll have a list of holidays for collection...

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:ba**********************************@c58g2000 hsc.googlegroups.com...
>On May 15, 12:00 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
>>Hi Seth,

Is this not more simple as it has to be in an array.

Dim myArray() as String = {"The first Day", "1/1/2008"}

I could not make more from the question of the OP.

:-)

Cor

"rowe_newsgroups" <rowe_em...@yahoo.comschreef in
berichtnews:fa********************************** @m45g2000hsb.googlegroups.com...

On May 14, 9:26 pm, "Brian" <bsgalla...@community.nospamwrote:
I am looking for a way to store maybe in an array or dictionary...
two
fields....
first field would be a string... second would be a date...
for example.. if i called up myinfo(0) it would show "the first Day"
"1/1/2008" ???
Brian

Sounds to me you just need to make a custom class that has two
properties, label and date:

//////////////
Public Class YourClassNameHere

Private _Label As String = String.Empty
Private _TheDate As DateTime = DateTime.Now

Public Sub New()

End Sub

Public Sub New(ByVal label As String, ByVal theDate As DateTime)
Me.New()

Me.Label = label
Me.TheDate = TheDate
End Sub

Public Property Label As String
Get
Return _Label
End Get
Set (ByVal value As String)
_Label = value
End Set
End Property

Public Property TheDate As DateTime
Get
Return _TheDate
End Get
Set (ByVal value As DateTime)
_TheDate = value
End Set
End Property

'// I typed this in the message so this statement might
'// not be formatted correctly
Public Overrides Function ToString() As String
Return String.Format("{0} {1}", Me.Label, Me.TheDate)
End Function

End Class
//////////////

Then you could just store these objects in any sort of IEnumerable
field (array, list, arraylist, etc) and then when you pull them out of
the array (or whatever) and call the .ToString() method, you will get
the string like you requested.

Thanks,

Seth Rowe [MVP]

The twist I saw was that he wanted to display both the label and the
date together, hence my ToString() override. Though you are correct,
the question was a bit vague to give an accurate answer.

Thanks,

Seth Rowe [MVP]

Jun 27 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.