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

Urgent: how to create Nested/Inner Property in CSharp

Hello folks,

Suppose I have a property called SortField

string SortField
{
get
{
if (SortField == string.Empty)
{
return "123";
}
return SortField;
}
set
{
SortField == value;
}
}

Now I want to have a nested property like "SortField.SomePropertyName" . How
do I do this. Can u help with a sameple code. Thanks alot.

Nov 15 '05 #1
4 1980
I think SortField would have to become a structure or class, and you would
have to have a property exposing an instance of this struct or class.
SortField would then have other properties.

"JollyK" <Jo****@email.com> wrote in message
news:e5**************@TK2MSFTNGP11.phx.gbl...
Hello folks,

Suppose I have a property called SortField

string SortField
{
get
{
if (SortField == string.Empty)
{
return "123";
}
return SortField;
}
set
{
SortField == value;
}
}

Now I want to have a nested property like "SortField.SomePropertyName" . How do I do this. Can u help with a sameple code. Thanks alot.

Nov 15 '05 #2
JollyK <Jo****@email.com> wrote:
Suppose I have a property called SortField

string SortField
{
get
{
if (SortField == string.Empty)
{
return "123";
}
return SortField;
}
set
{
SortField == value;
}
}
Firstly, there's a problem with the above - you'll get a stack
overflow, because your property would just keep calling itself. You
need a variable there, and use that in your get/set parts.
Now I want to have a nested property like "SortField.SomePropertyName" . How
do I do this. Can u help with a sameple code. Thanks alot.


You can't - there's no such thing as a nested property. What exactly
are you really after?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Normally you use a Property to get or set a protected Field.

string protected sp_SortField=String.Empty;
string public s_SortField
{
get
{
if (sp_SortField == String.Empty
return "123";
else
return sp_SortField;
}
set
{
if (value == StringEmpty)
sp_SortField = "123";
else
sp_SortField = value;
}
)

Normaly "get" is only used for returning the sp_SortField, but such a
condition should work.
It would be better if sp_SortField is set to a valid value from the
beginning.
In you example : if (SortField == string.Empty)
- when comparing SortField you are calling get, which again calls get etc.
Also a loop!
// Now I want to have a nested property like "SortField.SomePropertyName"
not quite sure what you mean by this. SortField is allready nested as it is,
which is bad.

Hope this helps
Mark Johnson, Berlin Germany
mj*****@mj10777.de

"JollyK" <Jo****@email.com> schrieb im Newsbeitrag
news:e5**************@TK2MSFTNGP11.phx.gbl...
Hello folks,

Suppose I have a property called SortField

string SortField
{
get
{
if (SortField == string.Empty)
{
return "123";
}
return SortField;
}
set
{
SortField == value;
}
}

Now I want to have a nested property like "SortField.SomePropertyName" . How do I do this. Can u help with a sameple code. Thanks alot.

Nov 15 '05 #4
Mark Johnson <mj*****@mj10777.de> wrote:
Normally you use a Property to get or set a protected Field.


I don't. If there's a field involved, it's always private as far as I'm
concerned (for production code, at least)...

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

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

Similar topics

6
by: Andy Baker | last post by:
Hi there, I'm learning Python at the moment and trying to grok the thinking behind it's scoping and nesting rules. I was googling for nested functions and found this Guido quote:...
4
by: Vedanta Barooah | last post by:
greetings.... in a python nested class is it possible to change the value of the parent class's variable without actually creating an instance of the parent class, consider this code: class...
4
by: Matthias Käppler | last post by:
Hello, I just wanted to ask, if an outer and a nested class share implementation details, e.g. in that both need to have access to a member of the nested class, is it common practice to simply...
2
by: Alfonso Morra | last post by:
I have a class that contains a nested class. The outer class is called outer, and the nested class is called inner. When I try to compile the following code, I get a number of errors. It is not...
0
by: Björn Bengtsson | last post by:
Hello! I have an urgent problem concerning ASP.NET, ADO.NET, SQL Server, XML and the TreeView control. I have two tables; one describing the products and one describing their relationships. A...
3
by: Guadala Harry | last post by:
I have this scenario: ASPX Page dynamically loads userControl1 - which in turn dynamically loads userControl2. UserControl2 contains a TextBox Web Server control. When a user clicks a button in...
4
by: LW | last post by:
Hi! I have a DataSet and a class in my Web Service. My output for example is: <OrderInfo> <CustomerID>VINET</CustomerID> <OrderID>10248</OrderID> <OrderDate>07/07/1996</OrderDate>...
5
by: Jake K | last post by:
What purpose does nesting a class inside another class typically server? Are there conditions where this would be beneficial? Thanks a lot.
3
by: kev | last post by:
Hello, I posted a question a while ago on tabbed pages, how to set it to invisible when the text box is empty.It was answered by Rick and the code ran perfectly. However, i tried using the same...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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,...

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.