collections

  • Thread starter Thread starter raulavi
  • Start date Start date
R

raulavi

vs2005 c#

how do i trap max number of row in a collection ?

lets say I can only have max of two rows in a collection

I have this property
const int MaxCount_SubmitterEDIContactInfos = 2;
private void validate_SubmitterEDIContactInfos()
{
if (_SubmitterEDIContactInfos.Count >
MaxCount_SubmitterEDIContactInfos)
Set Field Error ( "Too many rows ...bla,bla }
private List<PER_EDIContact> _SubmitterEDIContactInfos;
public List<PER_EDIContact> SubmitterEDIContactInfos
{
get { return _SubmitterEDIContactInfos; }

set
{
_SubmitterEDIContactInfos = value;
validate_SubmitterEDIContactInfos();
}
}

if i do 3 times
SubmitterEDIContactInfos.Add(new PER_EDIContact(file[c++]));
SubmitterEDIContactInfos.Add(new PER_EDIContact(file[c++]));
SubmitterEDIContactInfos.Add(new PER_EDIContact(file[c++]));

the set property is not hit at all, why?


set is only hit from constructor constructor

public SubmitterName()
{
SubmitterEDIContactInfos = new List<PER_EDIContact>();
}
 
thanks Peter, I beleive so
, How can I modify property to be checked ea time I add a row to collection ?
SubmitterEDIContactInfos.Add(new PER_EDIContact(file[c++]));
is adding to a list not a collection , why?
SubmitterEDIContactInfos i though was the collection
could you please, cexplain

Peter Bromberg said:
It looks to me like your set and get accesors are dealing with the list
itself, not an item in the list. The add method of List<T> does not use the
setter.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net


raulavi said:
vs2005 c#

how do i trap max number of row in a collection ?

lets say I can only have max of two rows in a collection

I have this property
const int MaxCount_SubmitterEDIContactInfos = 2;
private void validate_SubmitterEDIContactInfos()
{
if (_SubmitterEDIContactInfos.Count >
MaxCount_SubmitterEDIContactInfos)
Set Field Error ( "Too many rows ...bla,bla }
private List<PER_EDIContact> _SubmitterEDIContactInfos;
public List<PER_EDIContact> SubmitterEDIContactInfos
{
get { return _SubmitterEDIContactInfos; }

set
{
_SubmitterEDIContactInfos = value;
validate_SubmitterEDIContactInfos();
}
}

if i do 3 times
SubmitterEDIContactInfos.Add(new PER_EDIContact(file[c++]));
SubmitterEDIContactInfos.Add(new PER_EDIContact(file[c++]));
SubmitterEDIContactInfos.Add(new PER_EDIContact(file[c++]));

the set property is not hit at all, why?


set is only hit from constructor constructor

public SubmitterName()
{
SubmitterEDIContactInfos = new List<PER_EDIContact>();
}
 
Peter found an answer...

o.SubmitterEDIContactInfos[1].variable02 = "thiswaschanged";

your response gave me a tip...

I need to reference an item not the list as in
SubmitterEDIContactInfos.Add(new PER_EDIContact(file[c++]));



Peter Bromberg said:
It looks to me like your set and get accesors are dealing with the list
itself, not an item in the list. The add method of List<T> does not use the
setter.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net


raulavi said:
vs2005 c#

how do i trap max number of row in a collection ?

lets say I can only have max of two rows in a collection

I have this property
const int MaxCount_SubmitterEDIContactInfos = 2;
private void validate_SubmitterEDIContactInfos()
{
if (_SubmitterEDIContactInfos.Count >
MaxCount_SubmitterEDIContactInfos)
Set Field Error ( "Too many rows ...bla,bla }
private List<PER_EDIContact> _SubmitterEDIContactInfos;
public List<PER_EDIContact> SubmitterEDIContactInfos
{
get { return _SubmitterEDIContactInfos; }

set
{
_SubmitterEDIContactInfos = value;
validate_SubmitterEDIContactInfos();
}
}

if i do 3 times
SubmitterEDIContactInfos.Add(new PER_EDIContact(file[c++]));
SubmitterEDIContactInfos.Add(new PER_EDIContact(file[c++]));
SubmitterEDIContactInfos.Add(new PER_EDIContact(file[c++]));

the set property is not hit at all, why?


set is only hit from constructor constructor

public SubmitterName()
{
SubmitterEDIContactInfos = new List<PER_EDIContact>();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top