Re: struct
- From: Marv <Marv@xxxxxxxx>
- Date: Tue, 05 Apr 2005 14:52:43 -0700
Mohammad wrote:
14 7/8" x 8 1/2" wrote:
I want to use a struct to constrain a result.
The result is a string composed of several strings of fixed length;
Result is composed of 3 strings, each 4 char in length.
Can I build a struct that would enforce such a construct?
Yes you can, something like the following:
struct MyResult { private string s1 = string.Empty; private string s2 = string.Empty; private string s3 = string.Empty;
I tried doing this and VS.NET reports:
"cannot have instance field initializers in structs"
public string S1 { get { return s1; }
set { if ( value.Length <= 3 ) s1 = value; else throw new InvalidOperationExcpetion(); } }
// repeat for S2 and S3
}
.
- Follow-Ups:
- Re: struct
- From: Neno Loje [MVP C#]
- Re: struct
- References:
- struct
- From: 14 7/8\" x 8 1/2\"
- Re: struct
- From: Mohammad
- struct
- Prev by Date: Re: static abstract methods
- Next by Date: Re: DateTimePicker Problem
- Previous by thread: Re: struct
- Next by thread: Re: struct
- Index(es):