473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

OOP question - multiple value properties

I want to write a class that has multiple values associate to it

public class Person {
public string FirstName {get; set;}
public string LastName {get; set;}
public DateTime Date {get; set;}
}

For example, I want to create an object like this:

Person p = new Person();
p.FirstName = "John Smith";
p.FirstName.Description = "First Name Text";
p.FirstName.IsUsed = true;

How do I write it? do I need to write a wrapper class for "string" and
"DateTime"?


Nov 16 '05 #1
5 2609
Hi,

That will not compile, try something like this instead:

public struct Field
{
string Value;
string Description;
bool isUsed;
}
public class Person
{
Field _firstname;
public Field FirstName{ get; set ; }
}

then you can do:
Person p = new Person();
p.FirstName.Value = "John Smith";
p.FirstName.Description = "First Name Text";
p.FirstName.IsUsed = true;

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"NOSPAM" <no****@xsagfgsagsafg.com> wrote in message
news:ss********************@rogers.com...
I want to write a class that has multiple values associate to it

public class Person {
public string FirstName {get; set;}
public string LastName {get; set;}
public DateTime Date {get; set;}
}

For example, I want to create an object like this:

Person p = new Person();
p.FirstName = "John Smith";
p.FirstName.Description = "First Name Text";
p.FirstName.IsUsed = true;

How do I write it? do I need to write a wrapper class for "string" and
"DateTime"?


Nov 16 '05 #2
In this case, you will have to create an object that you want to expose
through the FirstName, LastName, etc, etc etc properties. You don't want to
expose a string, but rather, an object that has these properties that you
wish to expose.

As a result, you would have to declare the properties as getting/setting
types of this object.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"NOSPAM" <no****@xsagfgsagsafg.com> wrote in message
news:ss********************@rogers.com...
I want to write a class that has multiple values associate to it

public class Person {
public string FirstName {get; set;}
public string LastName {get; set;}
public DateTime Date {get; set;}
}

For example, I want to create an object like this:

Person p = new Person();
p.FirstName = "John Smith";
p.FirstName.Description = "First Name Text";
p.FirstName.IsUsed = true;

How do I write it? do I need to write a wrapper class for "string" and
"DateTime"?


Nov 16 '05 #3

Thanks a lot. You guys are awesome.. reply so fast!!!!!!!!
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:ez*************@TK2MSFTNGP14.phx.gbl...
Hi,

That will not compile, try something like this instead:

public struct Field
{
string Value;
string Description;
bool isUsed;
}
public class Person
{
Field _firstname;
public Field FirstName{ get; set ; }
}

then you can do:
Person p = new Person();
p.FirstName.Value = "John Smith";
p.FirstName.Description = "First Name Text";
p.FirstName.IsUsed = true;

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"NOSPAM" <no****@xsagfgsagsafg.com> wrote in message
news:ss********************@rogers.com...
I want to write a class that has multiple values associate to it

public class Person {
public string FirstName {get; set;}
public string LastName {get; set;}
public DateTime Date {get; set;}
}

For example, I want to create an object like this:

Person p = new Person();
p.FirstName = "John Smith";
p.FirstName.Description = "First Name Text";
p.FirstName.IsUsed = true;

How do I write it? do I need to write a wrapper class for "string" and
"DateTime"?



Nov 16 '05 #4

Thanks.. what about other non-string value? such as DateTime, int? any
suggestions?

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:ez*************@TK2MSFTNGP14.phx.gbl...
Hi,

That will not compile, try something like this instead:

public struct Field
{
string Value;
string Description;
bool isUsed;
}
public class Person
{
Field _firstname;
public Field FirstName{ get; set ; }
}

then you can do:
Person p = new Person();
p.FirstName.Value = "John Smith";
p.FirstName.Description = "First Name Text";
p.FirstName.IsUsed = true;

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"NOSPAM" <no****@xsagfgsagsafg.com> wrote in message
news:ss********************@rogers.com...
I want to write a class that has multiple values associate to it

public class Person {
public string FirstName {get; set;}
public string LastName {get; set;}
public DateTime Date {get; set;}
}

For example, I want to create an object like this:

Person p = new Person();
p.FirstName = "John Smith";
p.FirstName.Description = "First Name Text";
p.FirstName.IsUsed = true;

How do I write it? do I need to write a wrapper class for "string" and
"DateTime"?



Nov 16 '05 #5
With 2.0, you could create a generic type, which you would use to expose
the value as that type. Other than that, the only options you have now are
to expose it as an object (and force a cast), or create distinct types.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"NOSPAM" <no****@xsagfgsagsafg.com> wrote in message
news:FO********************@rogers.com...

Thanks.. what about other non-string value? such as DateTime, int? any
suggestions?

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote
in message news:ez*************@TK2MSFTNGP14.phx.gbl...
Hi,

That will not compile, try something like this instead:

public struct Field
{
string Value;
string Description;
bool isUsed;
}
public class Person
{
Field _firstname;
public Field FirstName{ get; set ; }
}

then you can do:
Person p = new Person();
p.FirstName.Value = "John Smith";
p.FirstName.Description = "First Name Text";
p.FirstName.IsUsed = true;

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"NOSPAM" <no****@xsagfgsagsafg.com> wrote in message
news:ss********************@rogers.com...
>I want to write a class that has multiple values associate to it
>
> public class Person {
> public string FirstName {get; set;}
> public string LastName {get; set;}
> public DateTime Date {get; set;}
> }
>
> For example, I want to create an object like this:
>
> Person p = new Person();
> p.FirstName = "John Smith";
> p.FirstName.Description = "First Name Text";
> p.FirstName.IsUsed = true;
>
> How do I write it? do I need to write a wrapper class for "string" and
> "DateTime"?
>
>
>
>
>
>



Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Max Weber | last post by:
Try to run the code below in a page. You will notice than when you switch the multiple attribute of the SELECT tag, only one option is displayed as selected although multiple options have ben...
3
by: Robson Carvalho Machado | last post by:
Dear friends, How can I create a Class and have multiple I/O porperties. Example: At my ASPX.VB I would like to pass test.ID = "G25" test.country = "US"
2
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
10
by: Kishor | last post by:
Hi, I am looking for the solution to my problem. this is related to inheritance (Inheriting properties of base class in multiple quantity) . I am writing code in VB.net language, I am having two...
5
by: Marina | last post by:
Hi, Let's say I bind the same column to multiple properties of one control (or even to the same property of several controls). If a user changes the value of the property in one control - I...
16
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
2
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code...
47
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
4
by: =?Utf-8?B?RGFuIFNoZXBoZXJk?= | last post by:
Is there a way to disable a number of fields (50+) using Visual Basic 2005? I have a window that used an imported control in vb 6 but now relies on .Net control.. The old logic was: Dim...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.