List Info

Thread: C-Sharp (C#) Group: Need some help with objects/classes




C-Sharp (C#) Group: Need some help with objects/classes
user name
2006-10-24 19:17:29
Hello,

 I'm trying to make my own object that holds a name of the
link, the
href of that link and if that link has any sublinks/hrefs.
Here is what
I have for my object (ArrayLink):



using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Text;
using System.Web;

namespace FAModel
{
    public class ArrayLink
    {
        private static string name;
        private static string href;
        private static ArrayList sublink;
        private static ArrayList subhref;

        public ArrayLink(string name2, string href2,
ArrayList
sublink2, ArrayList subhref2)
        {
            name = name2;
            href = href2;
            sublink = sublink2;
            subhref = subhref2;
        }

        public static string nameC
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        public static string hrefC
        {
            get
            {
                return href;
            }
            set
            {
                href = value;
            }
        }

        public static ArrayList sublinkC
        {
            get
            {
                return sublink;
            }
            set
            {
                sublink = value;
            }
        }

        public static ArrayList subhrefC
        {
            get
            {
                return subhref;
            }
            set
            {
                subhref = value;
            }
        }
    }
}



Here is my test code:



        ArrayLink test1 = new ArrayLink("asdf",
"asdf", null, null);
        ArrayLink test2 = new ArrayLink("asdf2",
"asdf", null, null);
        ArrayLink test3 = new ArrayLink("asdf3",
"asdf", null, null);
        ArrayLink test4 = new ArrayLink("asdf4",
"asdf", null, null);

 When I test in debug mode, after running through
test1...test4

 test1..test4 all have the test4 information of
"asdf4" and "asdf".
What am I doing wrong here? Thank you very much.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups-beta.google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Need some help with objects/classes
user name
2006-10-24 19:21:41
All of your member fields and properties are static references, so even though you are instantiating a new class, the constructor is still modifying the static value.  So only the most recently modified value will be what you see.  Remove the static modifier from your properties and your fields and it should behave how you expect it to.

On 10/24/06, c# < jobowoogmail.com">jobowoogmail.com> wrote:

Hello,

I'm trying to make my own object that holds a name of the link, the
href of that link and if that link has any sublinks/hrefs. Here is what
I have for my object (ArrayLink):



using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Text;
using System.Web;

namespace FAModel
{
  ; &nbsp;public class ArrayLink
 &nbsp; &nbsp;{
   ; &nbsp; &nbsp; private static string name;
&nbsp; &nbsp; &nbsp; &nbsp; private static string href;
&nbsp; &nbsp; &nbsp; &nbsp; private static ArrayList sublink;
&nbsp;   ; &nbsp; &nbsp;private static ArrayList subhref;

  ; &nbsp; &nbsp; &nbsp;public ArrayLink(string name2, string href2, ArrayList
sublink2, ArrayList subhref2)
  ; &nbsp; &nbsp; &nbsp;{
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ;name = name2;
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;href = href2;
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;sublink = sublink2;
  ; &nbsp; &nbsp; &nbsp; &nbsp;  subhref = subhref2;
  ; &nbsp; &nbsp; &nbsp;}

&nbsp; &nbsp; &nbsp; &nbsp; public static string nameC
&nbsp; &nbsp; &nbsp;   ;{
 &nbsp; &nbsp;   ; &nbsp; &nbsp; get
 &nbsp; &nbsp; &nbsp;   ; &nbsp; {
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; return name;
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;}
 &nbsp;   ; &nbsp; &nbsp; &nbsp; set
 &nbsp; &nbsp;   ; &nbsp; &nbsp; {
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; name = value;
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;}
   ; &nbsp; &nbsp; }

 &nbsp; &nbsp; &nbsp; &nbsp;public static string hrefC
&nbsp; &nbsp; &nbsp;   ;{
 &nbsp; &nbsp;   ; &nbsp; &nbsp; get
 &nbsp; &nbsp; &nbsp;   ; &nbsp; {
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; return href;
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;}
 &nbsp;   ; &nbsp; &nbsp; &nbsp; set
 &nbsp; &nbsp;   ; &nbsp; &nbsp; {
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; href = value;
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;}
   ; &nbsp; &nbsp; }

 &nbsp; &nbsp; &nbsp; &nbsp;public static ArrayList sublinkC
  ; &nbsp; &nbsp; &nbsp;{
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ;get
   ; &nbsp; &nbsp; &nbsp; &nbsp; {
 &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; return sublink;
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;}
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;set
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ;{
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; sublink = value;
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;}
   ; &nbsp; &nbsp; }

 &nbsp; &nbsp; &nbsp; &nbsp;public static ArrayList subhrefC
  ; &nbsp; &nbsp; &nbsp;{
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ;get
   ; &nbsp; &nbsp; &nbsp; &nbsp; {
 &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; return subhref;
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;}
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;set
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ;{
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; subhref = value;
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;}
   ; &nbsp; &nbsp; }
  ; &nbsp;}
}



Here is my test code:



&nbsp;   ; &nbsp; &nbsp;ArrayLink test1 = new ArrayLink("asdf&quot;, "asdf", null, null);
&nbsp; &nbsp; &nbsp;   ;ArrayLink test2 = new ArrayLink("asdf2", "asdf", null, null);
&nbsp; &nbsp;   ; &nbsp;ArrayLink test3 = new ArrayLink("asdf3", "asdf", null, null);
&nbsp; &nbsp; &nbsp;   ;ArrayLink test4 = new ArrayLink("asdf4", "asdf", null, null);

When I test in debug mode, after running through test1...test4

test1..test4 all have the test4 information of "asdf4" and "asdf".
What am I doing wrong here? Thank you very much.




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups-beta.google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Need some help with objects/classes
user name
2006-10-24 19:23:50
I tried what you said, but now when I compile, I get this
error:

An object reference is required for the nonstatic field,
method, or
property 'FAModel.ArrayLink.name'

Marty Thompson wrote:
> All of your member fields and properties are static
references, so even
> though you are instantiating a new class, the
constructor is still modifying
> the static value.  So only the most recently modified
value will be what you
> see.  Remove the static modifier from your properties
and your fields and it
> should behave how you expect it to.
>
> On 10/24/06, c# <jobowoogmail.com> wrote:
> >
> >
> > Hello,
> >
> > I'm trying to make my own object that holds a name
of the link, the
> > href of that link and if that link has any
sublinks/hrefs. Here is what
> > I have for my object (ArrayLink):
> >
> >
> >
> > using System;
> > using System.Collections;
> > using System.Collections.Generic;
> > using System.Data;
> > using System.Configuration;
> > using System.Text;
> > using System.Web;
> >
> > namespace FAModel
> > {
> >     public class ArrayLink
> >     {
> >         private static string name;
> >         private static string href;
> >         private static ArrayList sublink;
> >         private static ArrayList subhref;
> >
> >         public ArrayLink(string name2, string
href2, ArrayList
> > sublink2, ArrayList subhref2)
> >         {
> >             name = name2;
> >             href = href2;
> >             sublink = sublink2;
> >             subhref = subhref2;
> >         }
> >
> >         public static string nameC
> >         {
> >             get
> >             {
> >                 return name;
> >             }
> >             set
> >             {
> >                 name = value;
> >             }
> >         }
> >
> >         public static string hrefC
> >         {
> >             get
> >             {
> >                 return href;
> >             }
> >             set
> >             {
> >                 href = value;
> >             }
> >         }
> >
> >         public static ArrayList sublinkC
> >         {
> >             get
> >             {
> >                 return sublink;
> >             }
> >             set
> >             {
> >                 sublink = value;
> >             }
> >         }
> >
> >         public static ArrayList subhrefC
> >         {
> >             get
> >             {
> >                 return subhref;
> >             }
> >             set
> >             {
> >                 subhref = value;
> >             }
> >         }
> >     }
> > }
> >
> >
> >
> > Here is my test code:
> >
> >
> >
> >         ArrayLink test1 = new
ArrayLink("asdf", "asdf", null, null);
> >         ArrayLink test2 = new
ArrayLink("asdf2", "asdf", null, null);
> >         ArrayLink test3 = new
ArrayLink("asdf3", "asdf", null, null);
> >         ArrayLink test4 = new
ArrayLink("asdf4", "asdf", null, null);
> >
> > When I test in debug mode, after running through
test1...test4
> >
> > test1..test4 all have the test4 information of
"asdf4" and "asdf".
> > What am I doing wrong here? Thank you very much.
> >
> >
> > >
> >
>
> ------=_Part_13570_32367183.1161717701338
> Content-Type: text/html; charset=ISO-8859-1
>
> All of your member fields and properties are static
references, so even though you are instantiating a new
class, the constructor is still modifying the static
value.&nbsp; So only the most recently modified value
will be what you see.&nbsp; Remove the static modifier
from your properties and your fields and it should behave
how you expect it to.
> <br><br><div><span
class="gmail_quote">On 10/24/06, <b
class="gmail_sendername">c#</b>
&lt;<a href="mailto:jobowoogmail.com">jobowoogmail.com</a>&gt;
wrote:</span><blockquote
class="gmail_quote" style="border-left: 1px
solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex;
padding-left: 1ex;">
> <br>Hello,<br><br> I'm trying to make
my own object that holds a name of the link,
the<br>href of that link and if that link has any
sublinks/hrefs. Here is what<br>I have for my object
(ArrayLink):<br><br><br><br>using
System;
> <br>using System.Collections;<br>using
System.Collections.Generic;<br>using
System.Data;<br>using
System.Configuration;<br>using
System.Text;<br>using
System.Web;<br><br>namespace
FAModel<br>{<br>&nbsp;&nbsp;&nbsp;&a
mp;nbsp;public class ArrayLink
>
<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;private static string
name;<br>&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;private static string
href;<br>&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;private static ArrayList
sublink;<br>&nbsp;&nbsp;&nbsp;&nbsp;&a
mp;nbsp;&nbsp;&nbsp;&nbsp;private static
ArrayList
subhref;<br><br>&nbsp;&nbsp;&nbsp;&a
mp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public
ArrayLink(string name2, string href2, ArrayList
> <br>sublink2, ArrayList
subhref2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&
amp;nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name =
name2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;href =
href2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;sublink =
sublink2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&
amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
amp;nbsp;&nbsp;subhref =
subhref2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&
amp;nbsp;&nbsp;&nbsp;&nbsp;}<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;public static string nameC
>
<br>&nbsp;&nbsp;&nbsp;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p;&nbsp;&nbsp;&
amp;nbsp;&nbsp;&nbsp;set<br>&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;subhref =
value;<br>&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&am
p;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&a
mp;nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br>
> <br><br><br>Here is my test
code:<br><br><br><br>&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;ArrayLink test1 = new
ArrayLink(&quot;asdf&quot;,
&quot;asdf&quot;, null,
null);<br>&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;&nbsp;&nbsp;ArrayLink test2 = new
ArrayLink(&quot;asdf2&quot;,
&quot;asdf&quot;, null, null);
>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;ArrayLink test3 = new
ArrayLink(&quot;asdf3&quot;,
&quot;asdf&quot;, null,
null);<br>&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;&nbsp;&nbsp;ArrayLink test4 = new
ArrayLink(&quot;asdf4&quot;,
&quot;asdf&quot;, null, null);<br><br>
When I test in debug mode, after running through
test1...test4
> <br><br> test1..test4 all have the test4
information of &quot;asdf4&quot; and
&quot;asdf&quot;.<br>What am I doing wrong
here? Thank you very
much.<br><br><br></div><br>
> 
> ------=_Part_13570_32367183.1161717701338--


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups-beta.google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Need some help with objects/classes
user name
2006-10-24 19:27:36
Nevermind, I figured it out.

Here's my new class in case anyone else was wondering:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Text;
using System.Web;

namespace FAModel
{
    public class ArrayLink
    {
        private string name;
        private string href;
        private ArrayList sublink;
        private ArrayList subhref;

        public ArrayLink(string name2, string href2,
ArrayList
sublink2, ArrayList subhref2)
        {
            this.name = name2;
            this.href = href2;
            this.sublink = sublink2;
            this.subhref = subhref2;
        }

        public string nameC
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }

        public string hrefC
        {
            get
            {
                return this.href;
            }
            set
            {
                this.href = value;
            }
        }

        public ArrayList sublinkC
        {
            get
            {
                return this.sublink;
            }
            set
            {
                this.sublink = value;
            }
        }

        public ArrayList subhrefC
        {
            get
            {
                return this.subhref;
            }
            set
            {
                this.subhref = value;
            }
        }
    }
}

jobo wrote:
> I tried what you said, but now when I compile, I get
this error:
>
> An object reference is required for the nonstatic
field, method, or
> property 'FAModel.ArrayLink.name'
>
> Marty Thompson wrote:
> > All of your member fields and properties are
static references, so even
> > though you are instantiating a new class, the
constructor is still modifying
> > the static value.  So only the most recently
modified value will be what you
> > see.  Remove the static modifier from your
properties and your fields and it
> > should behave how you expect it to.
> >
> > On 10/24/06, c# <jobowoogmail.com> wrote:
> > >
> > >
> > > Hello,
> > >
> > > I'm trying to make my own object that holds a
name of the link, the
> > > href of that link and if that link has any
sublinks/hrefs. Here is what
> > > I have for my object (ArrayLink):
> > >
> > >
> > >
> > > using System;
> > > using System.Collections;
> > > using System.Collections.Generic;
> > > using System.Data;
> > > using System.Configuration;
> > > using System.Text;
> > > using System.Web;
> > >
> > > namespace FAModel
> > > {
> > >     public class ArrayLink
> > >     {
> > >         private static string name;
> > >         private static string href;
> > >         private static ArrayList sublink;
> > >         private static ArrayList subhref;
> > >
> > >         public ArrayLink(string name2, string
href2, ArrayList
> > > sublink2, ArrayList subhref2)
> > >         {
> > >             name = name2;
> > >             href = href2;
> > >             sublink = sublink2;
> > >             subhref = subhref2;
> > >         }
> > >
> > >         public static string nameC
> > >         {
> > >             get
> > >             {
> > >                 return name;
> > >             }
> > >             set
> > >             {
> > >                 name = value;
> > >             }
> > >         }
> > >
> > >         public static string hrefC
> > >         {
> > >             get
> > >             {
> > >                 return href;
> > >             }
> > >             set
> > >             {
> > >                 href = value;
> > >             }
> > >         }
> > >
> > >         public static ArrayList sublinkC
> > >         {
> > >             get
> > >             {
> > >                 return sublink;
> > >             }
> > >             set
> > >             {
> > >                 sublink = value;
> > >             }
> > >         }
> > >
> > >         public static ArrayList subhrefC
> > >         {
> > >             get
> > >             {
> > >                 return subhref;
> > >             }
> > >             set
> > >             {
> > >                 subhref = value;
> > >             }
> > >         }
> > >     }
> > > }
> > >
> > >
> > >
> > > Here is my test code:
> > >
> > >
> > >
> > >         ArrayLink test1 = new
ArrayLink("asdf", "asdf", null, null);
> > >         ArrayLink test2 = new
ArrayLink("asdf2", "asdf", null, null);
> > >         ArrayLink test3 = new
ArrayLink("asdf3", "asdf", null, null);
> > >         ArrayLink test4 = new
ArrayLink("asdf4", "asdf", null, null);
> > >
> > > When I test in debug mode, after running
through test1...test4
> > >
> > > test1..test4 all have the test4 information
of "asdf4" and "asdf".
> > > What am I doing wrong here? Thank you very
much.
> > >
> > >
> > > >
> > >
> >
> > ------=_Part_13570_32367183.1161717701338
> > Content-Type: text/html; charset=ISO-8859-1
> >
> > All of your member fields and properties are
static references, so even though you are instantiating a
new class, the constructor is still modifying the static
value.&nbsp; So only the most recently modified value
will be what you see.&nbsp; Remove the static modifier
from your properties and your fields and it should behave
how you expect it to.
> > <br><br><div><span
class="gmail_quote">On 10/24/06, <b
class="gmail_sendername">c#</b>
&lt;<a href="mailto:jobowoogmail.com">jobowoogmail.com</a>&gt;
wrote:</span><blockquote
class="gmail_quote" style="border-left: 1px
solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex;
padding-left: 1ex;">
> > <br>Hello,<br><br> I'm trying to
make my own object that holds a name of the link,
the<br>href of that link and if that link has any
sublinks/hrefs. Here is what<br>I have for my object
(ArrayLink):<br><br><br><br>using
System;
> > <br>using System.Collections;<br>using
System.Collections.Generic;<br>using
System.Data;<br>using
System.Configuration;<br>using
System.Text;<br>using
System.Web;<br><br>namespace
FAModel<br>{<br>&nbsp;&nbsp;&nbsp;&a
mp;nbsp;public class ArrayLink
> >
<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;private static string
name;<br>&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;private static string
href;<br>&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;private static ArrayList
sublink;<br>&nbsp;&nbsp;&nbsp;&nbsp;&a
mp;nbsp;&nbsp;&nbsp;&nbsp;private static
ArrayList
subhref;<br><br>&nbsp;&nbsp;&nbsp;&a
mp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public
ArrayLink(string name2, string href2, ArrayList
> > <br>sublink2, ArrayList
subhref2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&
amp;nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name =
name2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;href =
href2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp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&nbsp;{<b
r>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return
subhref;<br>&nbsp;&nbsp;&nbsp;&nbsp;&a
mp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&a
mp;nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&
amp;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
amp;nbsp;&nbsp;&nbsp;set<br>&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;subhref =
value;<br>&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&am
p;nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&a
mp;nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br>
> > <br><br><br>Here is my test
code:<br><br><br><br>&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;ArrayLink test1 = new
ArrayLink(&quot;asdf&quot;,
&quot;asdf&quot;, null,
null);<br>&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;&nbsp;&nbsp;ArrayLink test2 = new
ArrayLink(&quot;asdf2&quot;,
&quot;asdf&quot;, null, null);
> >
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;ArrayLink test3 = new
ArrayLink(&quot;asdf3&quot;,
&quot;asdf&quot;, null,
null);<br>&nbsp;&nbsp;&nbsp;&nbsp;&
;nbsp;&nbsp;&nbsp;&nbsp;ArrayLink test4 = new
ArrayLink(&quot;asdf4&quot;,
&quot;asdf&quot;, null, null);<br><br>
When I test in debug mode, after running through
test1...test4
> > <br><br> test1..test4 all have the
test4 information of &quot;asdf4&quot; and
&quot;asdf&quot;.<br>What am I doing wrong
here? Thank you very
much.<br><br><br></div><br>
> > 
> > ------=_Part_13570_32367183.1161717701338--


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups-beta.google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )