Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Vad menas med detta [DefaultValue(false)]?

Vad menas med detta [DefaultValue(false)]?

Scheduled Pinned Locked Moved C#
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tony_Joh
    wrote on last edited by
    #1

    Hej! Jag har en kod snutt här nedan där man sätter showDropDownButtons = false. Även om man inte gjorde det skulle showDropDownButtons vara initierat till false eftersom default initiering för bool är false. Jag har testat lite och även om jag skulle byta ut dennna [DefaultValue(false)] mot denna [DefaultValue(true)] skulle ShowDropDownButtons vara false. Uttrycket [DefaultValue(true)] utför allså ingen initiering. Jag kan inte förstå vad uttrycket [DefaultValue(false)] eller [DefaultValue(true)] har för någon nytta. Det fungerar precis lika bra om man utelämnar denna [DefaultValue(false)]. public class AdvPropertyColumn : PropertyEditColumn { public AdvPropertyColumn(string caption) : base(caption){} //konstructor private bool showDropDownButtons = false; [DefaultValue(false)] public bool ShowDropDownButtons { get { return showDropDownButtons; } set { if (showDropDownButtons != value) { Console.WriteLine("AdvPropertyColumn.Set.ShowDropDownButtons [showDropDownButtons != value]"); showDropDownButtons = value; base.OnChanged(InvalidationMode.ColumnWithoutHeader, false); } } }//end property ShowDropDownButton } //Tony

    J G 2 Replies Last reply
    0
    • T Tony_Joh

      Hej! Jag har en kod snutt här nedan där man sätter showDropDownButtons = false. Även om man inte gjorde det skulle showDropDownButtons vara initierat till false eftersom default initiering för bool är false. Jag har testat lite och även om jag skulle byta ut dennna [DefaultValue(false)] mot denna [DefaultValue(true)] skulle ShowDropDownButtons vara false. Uttrycket [DefaultValue(true)] utför allså ingen initiering. Jag kan inte förstå vad uttrycket [DefaultValue(false)] eller [DefaultValue(true)] har för någon nytta. Det fungerar precis lika bra om man utelämnar denna [DefaultValue(false)]. public class AdvPropertyColumn : PropertyEditColumn { public AdvPropertyColumn(string caption) : base(caption){} //konstructor private bool showDropDownButtons = false; [DefaultValue(false)] public bool ShowDropDownButtons { get { return showDropDownButtons; } set { if (showDropDownButtons != value) { Console.WriteLine("AdvPropertyColumn.Set.ShowDropDownButtons [showDropDownButtons != value]"); showDropDownButtons = value; base.OnChanged(InvalidationMode.ColumnWithoutHeader, false); } } }//end property ShowDropDownButton } //Tony

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      English forum...English questions please. Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

      1 Reply Last reply
      0
      • T Tony_Joh

        Hej! Jag har en kod snutt här nedan där man sätter showDropDownButtons = false. Även om man inte gjorde det skulle showDropDownButtons vara initierat till false eftersom default initiering för bool är false. Jag har testat lite och även om jag skulle byta ut dennna [DefaultValue(false)] mot denna [DefaultValue(true)] skulle ShowDropDownButtons vara false. Uttrycket [DefaultValue(true)] utför allså ingen initiering. Jag kan inte förstå vad uttrycket [DefaultValue(false)] eller [DefaultValue(true)] har för någon nytta. Det fungerar precis lika bra om man utelämnar denna [DefaultValue(false)]. public class AdvPropertyColumn : PropertyEditColumn { public AdvPropertyColumn(string caption) : base(caption){} //konstructor private bool showDropDownButtons = false; [DefaultValue(false)] public bool ShowDropDownButtons { get { return showDropDownButtons; } set { if (showDropDownButtons != value) { Console.WriteLine("AdvPropertyColumn.Set.ShowDropDownButtons [showDropDownButtons != value]"); showDropDownButtons = value; base.OnChanged(InvalidationMode.ColumnWithoutHeader, false); } } }//end property ShowDropDownButton } //Tony

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Short translation: "What does the [DefaultValue(true)] attribute do, as it doesn't affect the initial value of the property?" Answer: The attribute is used to specify what the default value of the property is supposed to be. It can be used by a visual designer or any other tool. The default value doesn't nessecarily have to be the same as the initial value. The default value is for an example used by the visual designer in Visual Studio when creating code for controls. A control usually have dozens of properties, but it only generate code to set the properties that differ from the default value. --- b { font-weight: normal; }

        J 1 Reply Last reply
        0
        • G Guffa

          Short translation: "What does the [DefaultValue(true)] attribute do, as it doesn't affect the initial value of the property?" Answer: The attribute is used to specify what the default value of the property is supposed to be. It can be used by a visual designer or any other tool. The default value doesn't nessecarily have to be the same as the initial value. The default value is for an example used by the visual designer in Visual Studio when creating code for controls. A control usually have dozens of properties, but it only generate code to set the properties that differ from the default value. --- b { font-weight: normal; }

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          It all looked like (Double)Dutch to me :) Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

          G 1 Reply Last reply
          0
          • J J4amieC

            It all looked like (Double)Dutch to me :) Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            Nope. Swedish. :) --- b { font-weight: normal; }

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups