Click here to Skip to main content
15,886,963 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem with arrays... Pin
Andres Coder4-Feb-04 3:29
Andres Coder4-Feb-04 3:29 
GeneralRe: Problem with arrays... Pin
Andres Coder4-Feb-04 3:29
Andres Coder4-Feb-04 3:29 
GeneralRe: Problem with arrays... Pin
Heath Stewart4-Feb-04 3:53
protectorHeath Stewart4-Feb-04 3:53 
GeneralRe: Problem with arrays... Pin
Andres Coder4-Feb-04 23:14
Andres Coder4-Feb-04 23:14 
GeneralRe: Problem with arrays... Pin
Jeff Varszegi12-Mar-04 9:00
professionalJeff Varszegi12-Mar-04 9:00 
QuestionRecord types in C# ? Pin
Andres Coder3-Feb-04 19:59
Andres Coder3-Feb-04 19:59 
AnswerRe: Record types in C# ? Pin
John Kuhn3-Feb-04 20:18
John Kuhn3-Feb-04 20:18 
GeneralRe: Record types in C# ? Pin
Heath Stewart3-Feb-04 20:37
protectorHeath Stewart3-Feb-04 20:37 
Technically, those aren't properties they're fields. The difference is that you can include validation code in property getters and setters (as well as other useful code, like recreating a native window handle or refreshing a drawing surface). With fields, you only get type safety.

To the original poster, you could always use a property to validate a param like so:
private int age;
public int Age
{
  get { return this.age; }
  set
  {
    if (age < 18) throw new ArgumentException("You're too young!", "value");
    this.age = value;
  }
}
Both structs and classes can use properties. If you do use properties (and you typically should), make sure you declare the fields as protected or private. If you're going to validate values using properties, make sure you force callers.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Record types in C# ? Pin
John Kuhn3-Feb-04 20:43
John Kuhn3-Feb-04 20:43 
GeneralRe: Record types in C# ? Pin
Andres Coder3-Feb-04 20:45
Andres Coder3-Feb-04 20:45 
GeneralRe: Record types in C# ? Pin
Heath Stewart4-Feb-04 3:29
protectorHeath Stewart4-Feb-04 3:29 
AnswerRe: Record types in C# ? Pin
Heath Stewart3-Feb-04 20:32
protectorHeath Stewart3-Feb-04 20:32 
GeneralRe: Record types in C# ? Pin
Andres Coder3-Feb-04 20:48
Andres Coder3-Feb-04 20:48 
Generalkernel process on c# Pin
laurentz_wei3-Feb-04 18:36
laurentz_wei3-Feb-04 18:36 
GeneralRe: kernel process on c# Pin
Heath Stewart3-Feb-04 20:21
protectorHeath Stewart3-Feb-04 20:21 
GeneralRe: kernel process on c# Pin
Mazdak3-Feb-04 20:24
Mazdak3-Feb-04 20:24 
GeneralOn Virtual And Override Pin
GetOn&GetGoing3-Feb-04 17:13
GetOn&GetGoing3-Feb-04 17:13 
GeneralRe: On Virtual And Override Pin
TigerNinja_3-Feb-04 17:38
TigerNinja_3-Feb-04 17:38 
GeneralRe: On Virtual And Override Pin
Heath Stewart3-Feb-04 20:18
protectorHeath Stewart3-Feb-04 20:18 
QuestionScrollBar bug? Pin
Meysam Mahfouzi3-Feb-04 16:58
Meysam Mahfouzi3-Feb-04 16:58 
Generalsome clarification on GDI+ vs. DIrectDraw Pin
SIDDHARTH_JAIN3-Feb-04 16:11
SIDDHARTH_JAIN3-Feb-04 16:11 
GeneralRe: some clarification on GDI+ vs. DIrectDraw Pin
Christian Graus3-Feb-04 17:44
protectorChristian Graus3-Feb-04 17:44 
GeneralRe: some clarification on GDI+ vs. DIrectDraw Pin
Michael Blome3-Feb-04 18:55
Michael Blome3-Feb-04 18:55 
GeneralRe: some clarification on GDI+ vs. DIrectDraw Pin
SIDDHARTH_JAIN4-Feb-04 11:36
SIDDHARTH_JAIN4-Feb-04 11:36 
GeneralPrepend to a file in C# Pin
pankajdaga3-Feb-04 13:27
pankajdaga3-Feb-04 13:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.