473,800 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Field in C#?

In new versions of MATLAB, I can do dynamic field like

userdata.('user name').electroc ardiogram = 4,

where 'username' can be replaced by any string variable. This made my
software design much neater. Does anybody know if C# support that? If so,
what's the syntax?

Thanks in advance.

Cheers,
Hoi
Jun 27 '08 #1
4 3277
On Wed, 30 Apr 2008 14:48:40 -0700, Hoi Wong <wo*****@stanfo rd.eduwrote:
In new versions of MATLAB, I can do dynamic field like

userdata.('user name').electroc ardiogram = 4,

where 'username' can be replaced by any string variable. This made my
software design much neater. Does anybody know if C# support that? If so,
what's the syntax?
The language doesn't support it directly, no. But you can easily
implement something using a Dictionary or indexer that does something
similar, depending on your specific need.

Pete
Jun 27 '08 #2
Hoi Wong <wo*****@stanfo rd.eduwrote:
In new versions of MATLAB, I can do dynamic field like

userdata.('user name').electroc ardiogram = 4,

where 'username' can be replaced by any string variable. This made my
software design much neater. Does anybody know if C# support that? If so,
what's the syntax?
You need to use a Dictionary<TKey ,TValue>:

userData["username"].Electrocardiog ram = 4;

(where userData is defined appropriately, of course).

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #3

"Hoi Wong" <wo*****@stanfo rd.eduwrote in message
news:fv******** **@news.Stanfor d.EDU...
In new versions of MATLAB, I can do dynamic field like

userdata.('user name').electroc ardiogram = 4,

where 'username' can be replaced by any string variable. This made my
software design much neater. Does anybody know if C# support that? If so,
what's the syntax?
I know you can do this with ADO.Net and C# when addressing fields in a
datatable dynamically addressing fields in the table by name. As a matter of
fact, I was taking a column/field name from a another table that
represented the fieldname in the table I wanted to access.

This just off the top of my head as to how it worked.

string fieldname = arow[brow["displayfldname "].Tostring()];

The field in arow was accessed via the name of the field that was in brow --
"displaynam e". Arow held the data that brow accessed to build dynamic
screens based on the tblScreenFields access into tblScreenData.

The ToString() was the key to getting it to work.

So, I don't see why you couldn't do the same in your example of addressing a
field dynamically, hopefully, and you can try it.

Jun 27 '08 #4
Sweet. Thanks for the pointer (no pun intended)!
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
Hoi Wong <wo*****@stanfo rd.eduwrote:
>In new versions of MATLAB, I can do dynamic field like

userdata.('use rname').electro cardiogram = 4,

where 'username' can be replaced by any string variable. This made my
software design much neater. Does anybody know if C# support that? If so,
what's the syntax?

You need to use a Dictionary<TKey ,TValue>:

userData["username"].Electrocardiog ram = 4;

(where userData is defined appropriately, of course).

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com

Jun 27 '08 #5

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

Similar topics

7
3418
by: Jack | last post by:
Hi, I am trying to test a sql statement in Access which gives me the error as stated in the heading. The sql statement is built as a part of asp login verification, where the userid and password are input in login screen. The password in the database is a number field. I am writing the dynamic sql statement as follows below. I believe I am going wrong in the password section of the code. I appreciate any help. Thanks. Regards.
1
1969
by: Simon Gare | last post by:
Hi I need to compare a dynamic field in an asp page to a field in another table, if there is no match then i would like to chane the row colour ( see code below). The problem Im having is that the comparison should be one of many entries in that db field, at the moment it only compares the first field in the db. Please Help
1
17682
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
1
1887
by: Giloosh | last post by:
Hello i have been trying to figure out this problem for a very long time now, and thought maybe its worth asking for some help. I want to figure out if there is a way to create a field in a select query that acts as a "COUNT" for the fields in the query. No matter what order the rest of the fields will be it will always remain in numerical order from 0+. Field one will be 1, field 2 will be 2, field 3 will be 3...etc. The reason i...
3
13756
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
2
3639
by: Luis Arvayo | last post by:
Hi, In c#, I need to dynamically create types at runtime that will consist of the following: - inherits from a given interface - will have a constructor with an int argument
4
5468
by: Bongard | last post by:
I have a dynamic range that I would like to use as a linked table into Access. The problem is that Access doesn't seem to want to to recognize the dynamic range when you click on "show named ranges" in the Link Spreadsheet wizard. The reason I want to use a dynamic range is because when the data in my excel spreadsheet changes the linked table will import blank rows that were previously used from the bottom of the spreadsheet. I can't...
20
6554
by: sirsnorklingtayo | last post by:
hi guys please help about Linked List, I'm having trouble freeing the allocated memory of a single linked list node with a dynamic char* fields, it doesn't freed up if I use the FREE() function in C.. But if I try to use a single linked list with a static char array fields I can free the memory allocated with out any problems using the FREE(). So, why freeing a single linked list with dynamic char* is hard and why the FREE() function is...
1
2969
by: jmartmem | last post by:
Greetings, I have a nagging problem with client-side dynamic dependent list boxes that perhaps someone can help me troubleshoot. I have a form with a series of dynamic dependent list boxes. Making a selection from list/box A (Qtr) selects a fiscal quarter, which then refreshes the values in list/box B (Mth), which shows the 3 months in that fiscal quarter, which then refreshes the values in list/box C (MthDate), which returns the date...
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.