Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Public properties without extra private property
Message
De
08/10/2014 11:54:02
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01608537
Message ID:
01608996
Vues:
38
This message has been marked as a message which has helped to the initial question of the thread.
>>You code doesn't make sense unless 'value' is a private field - and since you have no setter I assume it is not.
>
>Hi Viv,
>
>I want to verify my code with you:
>
>
> private byte[] _webGrpImg = new byte[0];
>        public byte[] Webgrpimg { get { return _webGrpImg; } 
>            set { value = _webGrpImg; 
>                  if (value.Length>0)
>                  {
>                      Webgrpimgd = DateTime.Now;
>                  }      
>            } 
>        }// webgrpimg. Group logo
>        
>        public DateTime? Webgrpimgd { get; set; } // webgrpimgd. Datetime stamp the group logo image was last updated
>
>will it only set date when I actually changed the image or it will always set the date? E.g. is this code OK or it's better to add some other means of checking if the image was added / changed?
>
>Thanks.

You have your set backwards. You want to set the value of _webGrpImg to value, not the other way around, Also you will be setting the date any time that the value is set to a non empty array, potentially including when the value is loaded from the database. You can use SequenceEqual (http://msdn.microsoft.com/en-us/library/vstudio/bb348567%28v=vs.100%29.aspx) before updating the field to determine if the value actually changed. Finally, you should be checking if value is null prior to checking its length.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform