index > Visual C# General > using a PointF type object in a Property

using a PointF type object in a Property

Anybody have any idea why I can't get/set a PointF variable that I've defined inside a class:

<snip>

private PointF _shoulderPoint;

internal PointF ShoulderPoint
{
get { return _shoulderPoint; }
set { _shoulderPoint = value; }
}

ShoulderPoint.X = (float)34.4
ShoulderPoint.Y = 25.5f

</snip>

both of the last two lines give me a compile error:

Error 1 Cannot modify the return value of 'XmlEditor.ArmInverseKinematics.ShoulderPoint' because it is not a variable C:\Alex\FlashDrive\Projects\RobotRenderer\RoboArmRobotRenderer1.0\Updated TRAL\Logitech Rumblepad version\XmlEditor\ArmInverseKinematics.cs 225 13 XmlEditor




Alex
Sweeps78

hi,

x and y are properties , i think you have to expose x and y in your application in properties as well like for example

private static PointF _point;

public static float myX

{

get { return _point.X; }

set { _point.X = value; }

}

public static PointF MyPoint

{

get { return _point; }

set { _point = value; }

}

hope this helps




http://fromisraeltolebanon.info
shakalama
Hi,
the reason why you can't do that is because PointF is a value type and so, the get property returns a copy of that struct. The compiler prevents you from changing that copy because it wouldn't work as you expected. To change that property you have to do it like this:

SholderPoint = new PointF(10.0f, 20.0f);
n0n4m3
Ah, I think I got you.

So, in order to change the values of a value type object, a new object of that same type has to be instantiated?

Thanks,

- Alex



Alex
Sweeps78

You are partially correct with regards to what n0n4m3 said. You can easily change the properties of a value type as we see in shakalama?? example (which may be one way for you to fix your problem).

The problem with setting a part of a value type without rebuilding it is with properties because to set the single value of the value type the property has to return the entire struct and then make available the individual value... when you try to set it the system doesn?? know what to do with this value as you are effectively setting (in your example) a float to a property that only accepts values of the type PointF.

Does this make things a little more clear?




Please visit http://www.brendansstudentloans.com to help me pay off my student loans a little faster
Brendan Grant
That does clear things up a bit.

I guess my only question is this. If I have the properties being set using:

SholderPoint = new PointF(X, Y);

Sweeps78

If you were to create a new PointF 10x a second your code wouldn?? be as efficient as it could be... but then is that really a problem?

Like so many possibilities of performance issues your best bet would be to do a little testing and determine some metrics for how bad creating 10 PointF?? a second every second would be for your application vs having a couple of properties that allow you direct access to the X and Y components. My guess... it wouldn?? be that bad.




Please visit http://www.brendansstudentloans.com to help me pay off my student loans a little faster
Brendan Grant

Find discussion on same topic @

http://www.codecomments.com/archive290-2005-5-503021.html




JMathews
Jaison LB
reply 8

You can use google to search for other answers

 

More Articles

• webbrowser and connection information
• Using TLS on LdapConneciton
• In C#, when I insert a record into Access tabel, why will it caus...
• How do you make a specific column in a datagrid readonly?
• convert from gray to color..
• converting aspx page to HTML
• static methods
• Export to Excel
• How to read JPEG in .NET
• evaluating variables with specific order?
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Index out of range - seraching Active Di
• How to connect SQL Server to VS?
• How to get the display information from
• ListBox
• datagridview navigation
• C#, Arrays, and Guids..OH MY!
• POPULATE A DROPDOWNLIST IN DATAGRID WITH
• Singleton pattern WITH command-line pass
• Auto Saving DataGridView Rows back to Ac
• PostMessages in to different app using C#
• Beginner help with Regular Expressions a
• Create a .swf file from a C# application
• data restriction
• Fast Range Search?
• Object Type Members in Reflection

Hot Articles

• ToolStripDropDownButton hot state wouldn
• How do I wait for a flag?
• Creating a setup project using Setup Pro
• NUnit forms test, Tricky exception:Resou
• Opening a folder from C#
• Graphics question
• Getting diffgram errors when saving data
• Collections and Arrays Question
• How C# talk with Flash Communiaction Ser
• How to send c++ unsigned char in C#
• Help about the taskbar...
• How do I open a an MDIform from a nonMDI
• Masked TextBox
• .NET feature that escapes certain charac
• XmlReader (ReadSubtree)

Recommend Articles

• File.Move with Large files
• file tree view using network
• Redirection of Standard Input for an Exe
• IEnumerable<T> compile error
• Personal website - save username
• creating a searchable pdf
• Building shared classes
• passing null to integer type parameter
• DllImport and thread stack debugging
• Difference Between selectionchanged and
• Can flash files be imported in Csharp wi
• How to inherit implementation from many
• problem with application.
• database DSN
• Windows defender (Beta 2) GUI