473,397 Members | 2,056 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,397 software developers and data experts.

question regarding C#.


Hi

I have class named Property:

enum PropertyType
{
text,
numeric
}

class Property
{
string stringValue;
long numericValue;
PropertyType type;
}

and a collection of properties,in the example the collection hold two
properties
a Url which is string type,and Size which is long type

I would like to be able to do something like the following

string Value1=Properties["Url"].value //this should return a string type
value
long Value2=Properties["Size"].value //this should return a long type
value

can't it be done?
thanks.
Jul 21 '05 #1
3 1355
Sure, but you need to adjust your code.

Here is what you need:
1) A property called Properties which points to something like a Hashtable
or dictionary.
2) A structure that holds all the properties such as Value.
3) The Hashtable would then contain references to the structure.

Keep in mind what your code is doing. First it needs to dereference the
Properties property. Next it sees the indexer so what gets returned from
Properties must have an indexer (like a collection or hashtable). Finally,
the item found in the collection must have a Value property.

"Julia" <co********@012.net.il> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...

Hi

I have class named Property:

enum PropertyType
{
text,
numeric
}

class Property
{
string stringValue;
long numericValue;
PropertyType type;
}

and a collection of properties,in the example the collection hold two
properties
a Url which is string type,and Size which is long type

I would like to be able to do something like the following

string Value1=Properties["Url"].value //this should return a string type
value
long Value2=Properties["Size"].value //this should return a long type
value

can't it be done?
thanks.

Jul 21 '05 #2
Julia,

You got your answer here, however it took some time.
Did you know that one of the three most active Microsoft develloper
newsgroups is

microsoft.public.dotnet.languages.csharp

Maybe for the next time

Cor

"Julia"
Hi

I have class named Property:

enum PropertyType
{
text,
numeric
}

class Property
{
string stringValue;
long numericValue;
PropertyType type;
}

and a collection of properties,in the example the collection hold two
properties
a Url which is string type,and Size which is long type

I would like to be able to do something like the following

string Value1=Properties["Url"].value //this should return a string type
value
long Value2=Properties["Size"].value //this should return a long type
value

can't it be done?
thanks.

Jul 21 '05 #3
Julia <co********@012.net.il> wrote:
I have class named Property:

enum PropertyType
{
text,
numeric
}

class Property
{
string stringValue;
long numericValue;
PropertyType type;
}

and a collection of properties,in the example the collection hold two
properties
a Url which is string type,and Size which is long type

I would like to be able to do something like the following

string Value1=Properties["Url"].value //this should return a string type
value
long Value2=Properties["Size"].value //this should return a long type
value

can't it be done?


No. The compiler can't know that Properties["Url"].Value is going to be
a string but Properties["Size"].Value is going to be a long. What you
*can* do is use a Hashtable or something similar and cast the result:

string value1 = (string) Properties["Url"].Value;
long value2 = (long) Properties["Size"].Value;

(Use a straight Hashtable and you don't need to use the .Value bit in
the first place.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4

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

Similar topics

2
by: Jo_Calico | last post by:
I love the Dynamic Drive cross browser marquee script. I'd like to make the text loop immediately after completion, so the beginning runs right after the end (does that make sense?). Could anyone...
3
by: Samuel | last post by:
I wrote a very simple httpmodule and tried to compile it with no success. This is my code: ============== Imports System Imports System.Web Imports Microsoft.VisualBasic NameSpace...
7
by: Squignibbler | last post by:
Hi all, I have a question regarding the C++ programming language regarding the nature of the relationship between pointers and arrays. If the statement MyArray is functionally identical to...
6
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is...
6
by: Jon | last post by:
All, I'm working in a fairly robust content management system for our company's websites, and have a question regarding the file and directory structure of the site. Currently, I'm populating...
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: 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: 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
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,...
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.