473,373 Members | 1,507 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,373 software developers and data experts.

Referencing Property as variable?

If I have a collection such as:
Person.addresscollection[0].Address1

and have a variable
myAddressField = "Address1"

how can I do something such as
Person.addresscollection[0].myAddressField

to reach the field "Address1"?

Thanks,
Brett

Jan 20 '06 #1
3 1016
You cannot the way you have it, but you can use reflection to dynamically
investigate and invoke objects. Take a look at the Type.GetProperty( ... ).
You will most likly have to wrap whatever you are doing in some method as
there is not built-in syntax for this.
"Brett Romero" <ac*****@cygen.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
If I have a collection such as:
Person.addresscollection[0].Address1

and have a variable
myAddressField = "Address1"

how can I do something such as
Person.addresscollection[0].myAddressField

to reach the field "Address1"?

Thanks,
Brett

Jan 20 '06 #2
> If I have a collection such as:
Person.addresscollection[0].Address1
and have a variable
myAddressField = "Address1"
how can I do something such as
Person.addresscollection[0].myAddressField
to reach the field "Address1"?

Thanks,
Brett


public class Address
{
private string myAddressField;

...

public string Address1
{
get{ return myAddressField; }
}
}
Jan 20 '06 #3
Peter, I could try something with Type.GetPropery but that means
needType.DLL will need to include all the DLLs of every type it needs.

I have an EXE project that file references this needType.DLL and A.DLL,
B.DLL, C.DLL. Those last three DLLs contain the types I'd need to use
with GetProperty in needType.DLL. If I were to reference the three
DLLs in needType.DLL, I'd have a lot of reduncy and complexity.
There'd probably be circular references.

Thanks,
Brett

Jan 21 '06 #4

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

Similar topics

3
by: DC Gringo | last post by:
I have an myPage.aspx with a myPage.ascx user control. The user control is the main header of the page. I have some conditional case code in the user control that I use which depends on a public...
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
3
by: DC Gringo | last post by:
I have an myPage.aspx with a myPage.ascx user control. The user control is the main header of the page. I have some conditional case code in the user control that I use which depends on a public...
2
by: HankD | last post by:
Hi, I am having a problem with instantiating two custom objects so they DO NOT point to the same memory location. What is happening is that changes I am making to my object1 are changing object2. I...
4
by: adam_kroger | last post by:
BRIEF EXPLANATION: I have 6 TextBoxes named LIS1, LIS2, LIS3, ... LIS6. I want to be able to reference them using a For/Next loop and either read ot write to them. In VBA I would use something...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.