473,385 Members | 1,588 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.

.NET syntax ??

Hi,

In recent .NET code I found a variable/reference like

item1.item2.item3

From my .NET courses I try to understand the meaning of this
....

Of course item1 must be a class/object. But what are the
possible meanings of item2.item3.

Does that mean that item2 is a nested class (inner class) in
class item1, or are there more explanations ??

E.g. item2 might be a property, but a property can't have
member/fields, so in that case item2.item3 is incorrect .NET
syntax ...

Or an interface maybe ??

Right ?

Still struggling with .NET code,

Some help would be nice.

Thanks,
P.
Nov 16 '05 #1
5 1191
Peter,

It depends on how it is being used. Generally though, if item1 is a
variable, then item2 is a property on that variable which exposes an
instance, and then item3 is a property on that result that is returned.

It could be used for static properties on types as well, where item1 is
a type, item2 and item3 are properties, but I would have to see the context.

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

"Peter" <An*****@work.nl> wrote in message
news:11***************@wgsvr01.wldelft.nl...
Hi,

In recent .NET code I found a variable/reference like

item1.item2.item3

From my .NET courses I try to understand the meaning of this
...

Of course item1 must be a class/object. But what are the
possible meanings of item2.item3.

Does that mean that item2 is a nested class (inner class) in
class item1, or are there more explanations ??

E.g. item2 might be a property, but a property can't have
member/fields, so in that case item2.item3 is incorrect .NET
syntax ...

Or an interface maybe ??

Right ?

Still struggling with .NET code,

Some help would be nice.

Thanks,
P.

Nov 16 '05 #2
item1; this is an instance of an object
item2; this is a property or public field of item1 that returns another
object
item3; this is a property or public field on item2

Properties are normally used to expose a private field, but can also return
a value that is calculated based on other internal values/states.

An interface only specifes what the signature of the class is, it doesn't
contain any code to return or perform calculations on any values.
Chris
"Peter" <An*****@work.nl> wrote in message
news:11***************@wgsvr01.wldelft.nl...
Hi,

In recent .NET code I found a variable/reference like

item1.item2.item3

From my .NET courses I try to understand the meaning of this
...

Of course item1 must be a class/object. But what are the
possible meanings of item2.item3.

Does that mean that item2 is a nested class (inner class) in
class item1, or are there more explanations ??

E.g. item2 might be a property, but a property can't have
member/fields, so in that case item2.item3 is incorrect .NET
syntax ...

Or an interface maybe ??

Right ?

Still struggling with .NET code,

Some help would be nice.

Thanks,
P.

Nov 16 '05 #3
> variable, then item2 is a property on that variable which
exposes an
instance,


You mean that property item2 operates on an object of class
item1.

Does next code make sense:

public class MyClass {
MyItem _item2;
public MyItem item2
{
get
{
return _item2;
}
}
}

public class MyItem
{
int _item3;
public MyItem item3
{
set
{
_item3 = value;
}
}
}

And then in the Main code:

MyClass item1;
item1.item2.item3 = 25;

Not quite sure ;)

Peter

Nov 16 '05 #4
Hi Peter,

Consider this:

class Items
{
public string item2;
}

now, if item3 is Length you can do

Items item1 = new Items();

Instead of doing

string s = item1.item2;
s.Length;

you can do

item1.item2.Length;

now, Length has a ToString() method so in effect you could do

item1.item2.Length.ToString();

In other words item1 has some properties, variables or methods in this
case one of them is item2.
item2 is another object with other properties variables or methods, in
this case one of them is item3.
You simply access public variables, properties, methods of the object
immediatly preceding '.' Any other '.' is irrelevant.

On Mon, 15 Nov 2004 18:28:29 +0100, Peter <An*****@work.nl> wrote:
variable, then item2 is a property on that variable which

exposes an
instance,


You mean that property item2 operates on an object of class
item1.

Does next code make sense:

public class MyClass {
MyItem _item2;
public MyItem item2
{
get
{
return _item2;
}
}
}

public class MyItem
{
int _item3;
public MyItem item3
{
set
{
_item3 = value;
}
}
}

And then in the Main code:

MyClass item1;
item1.item2.item3 = 25;

Not quite sure ;)

Peter


Yes, this is correct. It does not need to be properties.

int n = 12345;
n.ToString().Length.ToString()[0].ToString().Length;

is perfectly legal.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #5

"Peter" <An*****@work.nl> wrote in message
news:11***************@wgsvr01.wldelft.nl...
Hi,

In recent .NET code I found a variable/reference like

item1.item2.item3

From my .NET courses I try to understand the meaning of this


Perhaps it's simpler if you expand it. It's the same as temp2 in:

temp = item1.item2;
temp2 = temp.item3

That is, item2 is a property of item1. item1.item2 is itself an object
(everything in .NET is an object), and item3 is a property of *that* object.
Nov 16 '05 #6

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
22
by: Tuang | last post by:
I'm checking out Python as a candidate for replacing Perl as my "Swiss Army knife" tool. The longer I can remember the syntax for performing a task, the more likely I am to use it on the spot if...
14
by: Sandy Norton | last post by:
If we are going to be stuck with @decorators for 2.4, then how about using blocks and indentation to elminate repetition and increase readability: Example 1 --------- class Klass: def...
16
by: George Sakkis | last post by:
I'm sure there must have been a past thread about this topic but I don't know how to find it: How about extending the "for <X> in" syntax so that X can include default arguments ? This would be very...
23
by: Carter Smith | last post by:
http://www.icarusindie.com/Literature/ebooks/ Rather than advocating wasting money on expensive books for beginners, here's my collection of ebooks that have been made freely available on-line...
19
by: Nicolas Fleury | last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $...
4
by: Jeremy Yallop | last post by:
Looking over some code I came across a line like this if isalnum((unsigned char)c) { which was accepted by the compiler without complaint. Should the compiler have issued a diagnostic in this...
177
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are...
4
by: Bob hotmail.com> | last post by:
Everyone I have been spending weeks looking on the web for a good tutorial on how to use regular expressions and other methods to satisfy my craving for learning how to do FAST c-style syntax...
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
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?
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
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.