Re: question from C# novice

From: Patrice (nobody_at_nowhere.com)
Date: 03/17/05


Date: Thu, 17 Mar 2005 20:31:24 +0100


 public double Value //Using another name doesn't help
 {
 get
 {
 return Value;
 }
set
{
 Value = value; // Calls itself until it crashes...
}

Generally the get/set just updates a private variable. Here you are using
the name of the property that is you are calling again the "set" that calls
again the "set" and so on until it crashes...

Patrice

-

"Jose" <Jose@discussions.microsoft.com> a écrit dans le message de
news:8F9FE381-ADA8-42D0-B308-E5275C26E8ED@microsoft.com...
> I'm confused - are you saying that I can't have a variable named Value? I
> know "value" is a special word but I didn't know that Value was also
reserved.
>
> "SB" wrote:
>
> > Your problem is that inside your setter, you are calling your setter
> > again....which will cause a stack overflow as you have seen :) Where
is
> > your variable to hold Value? That is what you should be
setting/getting.
> >
> > HTH,
> > -sb
> >
> > "Jose" <Jose@discussions.microsoft.com> wrote in message
> > news:BE5B066F-6499-45C3-8E4A-24554CC9442B@microsoft.com...
> > > When I try to compile the code below I receive a first chance
exception.
> > > I've
> > > noticed from searching on the web that some people choose to ignore
first
> > > chance exceptions. Is this common practice? Do you guys see anything
wrong
> > > with my code or should I ignore the exception it generates?
> > >
> > > <Using directives here>
> > > namespace Settings
> > > {
> > >
> > > enum DisplacementUnits { Feet, Kilofeet, Meters, Kilometers,
> > > NauticalMiles };
> > >
> > > abstract class Variable
> > > {
> > > public abstract int Unit
> > > {
> > > get;
> > > set;
> > > }
> > > public double Value //Using another name doesn't help
> > > {
> > > get
> > > {
> > > return Value;
> > > }
> > > set
> > > {
> > > Value = value; //Generates a A first chance exception of type
> > > 'System.StackOverflowException'
> > > }
> > >
> > > }
> > > }
> > >
> > > class DisplacementVariable : Variable
> > > {
> > > public override int Unit
> > > {
> > > get
> > > {
> > > return Unit;
> > > }
> > > set
> > > {
> > > Console.WriteLine("set");
> > > }
> > > }
> > >
> > > public DisplacementVariable()
> > > {
> > > Unit = (int)DisplacementUnits.Feet;
> > > Value = 0;
> > > }
> > > public DisplacementVariable(double value, int unit)
> > > {
> > > Unit = unit;
> > > Value = value;
> > > }
> > > }
> > >
> > > class Settings
> > > {
> > > double someVar1;
> > > string someVar2;
> > >
> > >
> > > static void Main(string[] args)
> > > {
> > > DisplacementVariable x = new DisplacementVariable(0,0);
> > > Console.WriteLine("in main..");
> > > Console.ReadLine();
> > > }
> > > }
> > > }
> > >
> > > I'm using VS2005 beta1.
> >
> >
> >



Relevant Pages

  • Re: Closing Port 25 for Internal Clients
    ... 'See how your system says "updates are available". ... Reluctant or recalcitrant users get sick of me calling them, after checking their WSUS, and reminding them 'That yellow box thing has been popping up every few hours for the past 10 days, are you going to listen to me or not?'. ... Your 'edge device' provides no protection to LAN devices. ... mickm at mickmalloy dot dyndns dot org ...
    (microsoft.public.windows.server.sbs)
  • Re: XMLEncoder problem
    ... If the method setWords() is called it initializes both wordList and ... Somehow XMLDecoder is initializing wordList without calling ... That's why you never see the setter called. ...
    (comp.lang.java.programmer)
  • Re: SBS loses installed licenses
    ... download the 10.1.7 MR version and upgrade ... their software - you need to have an active maintenance contract to get ... updates. ... Calling an illegal alien an "undocumented worker" is like calling a ...
    (microsoft.public.windows.server.sbs)
  • Re: Pc Sending Spam Emails, No Trojan or Virus Found - Please Help!
    ... Okay, I've done a few more scans and updates, plus re-installed Norton just ... These sites are for downloading Anti-Malware and Anti-Spyware tools, ... Calling an illegal alien an "undocumented worker" is like calling a ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Accessors in Python (getters and setters)
    ... something else (user interaction, physical events); ... intermediation of setter methods that do nothing else but set the state. ... calling a setter function that does nothing else but directly setting the ... The conceptual difference is that a function call is more like an "event", ...
    (comp.lang.python)