Author Topic: Is it good to record a line by converting its propeties to strings?  (Read 2226 times)

0 Members and 1 Guest are viewing this topic.

waterharbin

  • Guest
Hi
I want to record a lots of lines. Basicly,people will tell me to define a List<Line> to hold them. But I have a different idea. How about we change the line's propeties into a combined string, and define a List<String> to hold the strings. For example:
Code: [Select]
Line myLine as new Line;
String myStr as new String;
myStr = (myLine.StartPoint.x).ToString() + "@" +(myLine.StartPoint.Y).ToString() + "@" + (myLine.StartPoint.Z).ToString();
List<String> myStrList as new List<String>;
myStrList.Add(myStr);
As you can see, I use the "@" as the separater so you can get the propetise back later.
I found this idea a little strange, is it a good idea? At least, I think this will help when you need to record extra properties not officially defined by the AutoCAD. So, how do you say?

trembre

  • Guest
Re: Is it good to record a line by converting its propeties to strings?
« Reply #1 on: June 04, 2012, 09:53:54 PM »
This reads like the kind of thing I'd have done before I stopped using self-taught VBA-isms and understood what I could do with my own custom classes. 

First off, if I understand you correctly, I would determine whether that extra information you want to record isn't available elsewhere.  If not, then I'd brush up on custom class creation, it'll make your life much easier.

If you don't need to record that extra information, there's no point in complicating things beyond List<Line>

waterharbin

  • Guest
Re: Is it good to record a line by converting its propeties to strings?
« Reply #2 on: June 04, 2012, 10:49:56 PM »
Hi
I knew I can write my own custom classes to do that. But I also knew the prototpye of the String is a Structure, not a Class. I seem to remeber that a Structure costs less than a Class. And when a huge number is involved, Structures can save some resources. That's why I want to use the Strings.
For extra information, there are lots of them. For example, I may need the mass, stiffness for computing. I don't think AutoCAD has something like those,haha.

TheMaster

  • Guest
Re: Is it good to record a line by converting its propeties to strings?
« Reply #3 on: June 05, 2012, 12:04:16 AM »
Hi
I knew I can write my own custom classes to do that. But I also knew the prototpye of the String is a Structure, not a Class. I seem to remeber that a Structure costs less than a Class. And when a huge number is involved, Structures can save some resources. That's why I want to use the Strings.
For extra information, there are lots of them. For example, I may need the mass, stiffness for computing. I don't think AutoCAD has something like those,haha.

String is a class, not a struct.

A struct is a type that is passed by value, and if strings were structs or value types, then
an entire string's contents would need to be copied when it is passed as an argument to
a method, etc.

you're focusing on some obscure aspect of the underlying type
system with an idea that it will serve the purpose of efficiency.

The problem with storing Line entities in a List<Line> is that they are not usable outside
the scope of the transaction you get them from, and so you can't simply keep them around
for use whenever you need them.

How you should persist your information about Lines (or any other object for that matter)
depends on what you need to do with it. For example, you could persist data in the form
of XML or JSON (both of which can be represented as strings, BTW), or you could use your
own custom class or struct and store what you need in them.
« Last Edit: June 05, 2012, 12:40:26 AM by TheMaster »