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

Jess Liberty's C# book on C#

Hi,
can someone explain the following extract from Jess Liberty's C# book
(very end of chapter on structs)?
"Be careful about using properties. Although these allow you to
support encapsulation by making the actual values private, the
properties themselves are actually member methods and you cannot call
a member method until you initialize all the member variables". I
don't understand what he means.
Cheers,
Emmanuel
Nov 17 '05 #1
6 1995
I guess that means ... that anybody can write and publish book ;)
Cheers,
Nick

"Emmanuel Godet" <eg****@equisys.com> wrote in message
news:8f*************************@posting.google.co m...
Hi,
can someone explain the following extract from Jess Liberty's C# book
(very end of chapter on structs)?
"Be careful about using properties. Although these allow you to
support encapsulation by making the actual values private, the
properties themselves are actually member methods and you cannot call
a member method until you initialize all the member variables". I
don't understand what he means.
Cheers,
Emmanuel

Nov 17 '05 #2
In message <8f*************************@posting.google.com> , Emmanuel
Godet <eg****@equisys.com> writes
Hi,
can someone explain the following extract from Jess Liberty's C# book
(very end of chapter on structs)?
"Be careful about using properties. Although these allow you to
support encapsulation by making the actual values private, the
properties themselves are actually member methods and you cannot call
a member method until you initialize all the member variables". I
don't understand what he means.


Nor do I. The compiler barfs on a struct without a constructor, a struct
constructor which doesn't initialise all fields, and any attempt to
access an uninitialised struct. So how can you get your hands on a
struct which has uninitialised member variables?

--
Steve Walker
Nov 17 '05 #3
Hello!

Have you already read and understood "Inside C#" from MS Press, otherwise,
you could consider that as an alternative.
Best regards,

Henrik Dahl

"Emmanuel Godet" <eg****@equisys.com> wrote in message
news:8f*************************@posting.google.co m...
Hi,
can someone explain the following extract from Jess Liberty's C# book
(very end of chapter on structs)?
"Be careful about using properties. Although these allow you to
support encapsulation by making the actual values private, the
properties themselves are actually member methods and you cannot call
a member method until you initialize all the member variables". I
don't understand what he means.
Cheers,
Emmanuel

Nov 17 '05 #4
If you know what that paragraph means, it'd be easier and far more helpful
to help describe what it's saying instead of pointing out yet more books to
read. Not everyone can afford to buy and read each and every book about a
particular subject.

"Henrik Dahl" <He********@community.nospam> wrote in message
news:Ok**************@TK2MSFTNGP15.phx.gbl...
Hello!

Have you already read and understood "Inside C#" from MS Press, otherwise,
you could consider that as an alternative.
Best regards,

Henrik Dahl

"Emmanuel Godet" <eg****@equisys.com> wrote in message
news:8f*************************@posting.google.co m...
Hi,
can someone explain the following extract from Jess Liberty's C# book
(very end of chapter on structs)?
"Be careful about using properties. Although these allow you to
support encapsulation by making the actual values private, the
properties themselves are actually member methods and you cannot call
a member method until you initialize all the member variables". I
don't understand what he means.
Cheers,
Emmanuel


Nov 17 '05 #5
I believe he is saying the you cannot use properties to assign a
member's initial value:

MyClass m = new MyClass(); // initialization must be done here.
m.A = 1; // you can only change a value, not initially assign
it here.
m.B = 2;
--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"Emmanuel Godet" <eg****@equisys.com> wrote in message
news:8f*************************@posting.google.co m...
Hi,
can someone explain the following extract from Jess Liberty's C# book
(very end of chapter on structs)?
"Be careful about using properties. Although these allow you to
support encapsulation by making the actual values private, the
properties themselves are actually member methods and you cannot call
a member method until you initialize all the member variables". I
don't understand what he means.
Cheers,
Emmanuel

Nov 17 '05 #6
Consider this struct

struct Point
{
int x;
public int X
{
get{ return x; }
set{ x = value; }
}
int y;
public int Y
{
get{ return y; }
set{ y = value; }
}
}

now lets use it in some code

Point p = new Point();
p.X = 10;
p.Y = 20;

this works as the ctor initializes the stucts memory to 0.

However if we change the code to:

Point p;
p.X = 10;
p.Y = 20;

This won't compile as the memory has not been initialized and the property sets are actually method calls.

The only way to make code like that work is to have the fields as public then you can write

Point p = new Point();
p.x = 10;
p.y = 20;

which is allowed. Until you have initialized every field of the struct you cannot call a method on it. You can do this initialization manually or via a constructor. Jesse is saying that you cannot perform this initialization via property sets as they are in fact method calls

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi,
can someone explain the following extract from Jess Liberty's C# book
(very end of chapter on structs)?
"Be careful about using properties. Although these allow you to
support encapsulation by making the actual values private, the
properties themselves are actually member methods and you cannot call
a member method until you initialize all the member variables". I
don't understand what he means.
Cheers,
Emmanuel

Nov 17 '05 #7

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

Similar topics

24
by: asj | last post by:
It seems that Microsoft may be slowly phasing away Passport, which had been one of the hyped components of the eroded dotnet hype....bye bye, passport, we hardly knew ye! bwahahahbwahahaha!!!!! ...
6
by: Zach | last post by:
If someone has studied the book, could he or she then please tell me how to paste an example, eg. 4-1 on pages 81-2, into Visual Studio .NET and make it run? The closest I got to running it was to...
3
by: Basil Fawlty | last post by:
Hi everyone, I could use some help in converting a simple Liberty BASIC program toa VB.NET 2003 SE program. I have built the simple form with a label, text box and button, Under the button I...
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: 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: 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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.