|
BTW: Are you creating all this by hand? If so, why?
You do realise that VS can create a "tidier" version of all that for you automatically?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Then where is the code to display the form? It won't appears magically... (except for the initial form which is initialized by the application).
Philippe Mori
|
|
|
|
|
Please let me know the name of your software so I never use it. Anything with a namespace of TCPReader, but you don't know how to figure out why a form isn't appearing, is very scary.
--
Chizl
|
|
|
|
|
The short version: "How do you use Enums in C# as: structural element ? design strategy ? Do you see any special "danger" in using elaborate Enum structures ?"
In the last few years, somehow I have moved to more, and more, frequent use of Enums in C# ... without having, at any point in time, made a conscious decision to do so (though reading code examples by people I consider .NET gurus here on CP, and on StkO, is probably an influence). Of course, I like the idea that Enums are memory-parsimonious, simple, relatively light-weight, and I like what using the [Flags] attribute lets you do. I really like the fact Enum values are compile-time constants that can be used in a 'Switch statement block.
I've come to believe that use of Enums + Interfaces (and generic Interfaces) are, as well, very powerful tools for application design (this may be so obvious to many of you reading this that you may wonder: "where has he been ?").
I've also come to think of Enums as a form of "self-documentation" in Code, as a design-organizing principle ... I am very curious how you react to that idea.
I have, lately, been reading the historical record of various advices on best practices with Enums given my MS over time.
And, I am aware of the argument/concept that creating an app with a large dependency on Enums may result in "future fragility:" an update changes one of the Enums ... adds a new value, makes some Enum value == 0 ... and code-breaks all over the place. I wonder if there's any qualitative difference ... vis a vis an app's future modifications ... between dependency-with-Enums and dependency because of reliance on Interfaces, or Class/Struct OOP design ?
I've recently been experimenting with Enums, doing things using "nested Enums:
[Description("The Play")]
[Status("Tests Valid 03/23/2016")]
public enum ThePlay
{
Act1 = 1, Act2 = 2, Act3 = 3
}
[Description("The Murder")]
[Status("Act1 changed 12/02/2015")]
public enum Act1
{
Scene1Suspects = 1, Scene2TheDetectives = 2
}
[Description("The Suspects")]
[Status("Scene1Suspects added 12/02/2015")]
[Flags]
public enum Scene1Suspects
{
None = 0x0,
Butler = 0x2,
LadyX = 0x4,
LordX = 0x8,
Gardener = 0x10
} And, I find it easy to parse these (using Reflection) and construct a UI (like a TreeView) at run-time.using the Enums' names, values, and the content of any Attributes; it's easy to detect if the Enum uses 'Flags, relatively easy to make (using a TreeView) a node structure that enforces multiple child node checkboxes to be checked ... and, by the same token, easy enough to create a node structure that allows only one child node CheckBox to be checked
Possible drawbacks to using Enums as more than "simple" design-elements ?
1. no generic constraints of Type 'Enum allowed in generic objects: Jon Skeet has a "work-around" for this (which I haven't tried): [^]
2. more work required to serialize an Enum so it retains "Label" content.
3. Enums are not as "Type safe;" they're just "dumb wrappers" over some block of allocated integral Types.
4. an example of arguments against using Enums is presented in this article which provides code for a Class based alternative: [^].
appreciate your response.
thanks, Bill
«The truth is a snare: you cannot have it, without being caught. You cannot have the truth in such a way that you catch it, but only in such a way that it catches you.» Soren Kierkegaard
|
|
|
|
|
|
Thanks, Garth, I will take another look at Sergey's article.
I am looking for "opinions," here, not necessarily "answers"
cheers, Bill
«The truth is a snare: you cannot have it, without being caught. You cannot have the truth in such a way that you catch it, but only in such a way that it catches you.» Soren Kierkegaard
|
|
|
|
|
A few notes on my opinions/usages on enums:
1. I quite love enums. Especially when you use them to specify an argument to a function
Like enforcing a constraint,
enum month { jan, feb, ... , dec };
2. I know there are pitfalls, but if you know them, enums are really powerful. They are self-documenting. Code looks much better at the point of call.
Just imagine:
var lines = x.Split( new[] {"\r\n"}, SplitOptions.RemoveEmptyEntries);
The latter argument could have been a boolean, but then the code would have been much harder to understand:
<br />
var lines = x.Split( new[] {"\r\n"}, true);
3. One of the possible problems when using enums is when you add a new value. In this case, you'll pretty much need to update all the code that used switch -es based on this enum. That's why I strive to have as few functions that require a switch based on all possible values.
4. About "future fragility": If other code depends on exact enum values, I usually put a comment on top of the enum
enum month { jan = 1, feb = 2, ... , dec = 12 };
5. "Nested" enums. I have used something more or less similar in my code, but never more than 2 levels deep. So far, I haven't encountered any pitfalls.
6. Took a look at the Class based alternative - clearly, there are some scenarios for it, but I think most of the time, it's overkill (my personal opinion, of course )
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
Thanks, John, for your comments !
I'm doing an interesting experiment right now, kind of "pushing the limits" of what one can do with Enums, using nesting, Attributes, etc. I may have gotten a little "carried away" with it, and will re-evaluate it after I restore my big-picture perspective ... look at what it would mean to use classes, and structs (with named constants, etc.) to replace the Enums, taking advantage of inheritance.
See what happens when you don't have to work for a living ?
cheers, Bill
«The truth is a snare: you cannot have it, without being caught. You cannot have the truth in such a way that you catch it, but only in such a way that it catches you.» Soren Kierkegaard
|
|
|
|
|
BillWoodruff wrote: Thanks, John, for your comments !
My pleasure
I'm quite interested in the results, since as I said, I pretty much love Enums, especially how they are implemented in C# (clearly, they're not perfect, but I would say I'm quite happy with the current implementation).
About "pushing the limits" - I used to sometimes do that when I actually had the time , back in my C++ days (for instance, SMART_ASSERT).
Some of my "pushing the limits" experiments ended up as purely theoretical - that is, it's cool to be able to do it, but who's ever gonna understand/use it?
I am aware of the named constants instead of enums, I think I actually saw some java examples of it a long time ago. My take is that with disciplined (and smart) programmers, usually enums are enough.
And if we add the multitude of tools we now have at our disposal (such as, Resharper comes to mind; go inside the body of an enum switch -> Alt-Enter -> generate case labels), I still favor enums (vs named constants).
BillWoodruff wrote: See what happens when you don't have to work for a living ?
He he, don't we all wish to be able to not work for a living?
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
|
|
Let me clarify this, when you create a ADO.NET application, you will need to have SQL Server to handle the database layer in client computer.How can we have a exe file from our ADO.NET application that it does not need to work with SQL server to connect the database file (like working with txt files to save data).The question is whether to exist a answer for this or not.
|
|
|
|
|
|
Let me clarify. As 'Griff already said, you don't need SQL Server, at all! ADO.NET can use any database engine that has an ADO.NET provider, which is pretty much all of them. There's eve support for some stuff that doesn't use a database engine! Though with these, you lose a lot of querying capability because, well, that's always handled by the database engine.
To answer your question (again), Yes!
|
|
|
|
|
Install it on a server instead and include that in your connection string.
Saying that, the others are correct in pointing out that you don't need Sql Server to use ADO.NET.
This space for rent
|
|
|
|
|
I am trying to make a map of several states with specific points and while I have the Longitude and latitude of the points is there functions that will simply take the longitude and latitude,and generate the x and y?
Thanks!
|
|
|
|
|
Googling "convert latitude and longitude to state plane coordinates"[^] results in a wealth of sources of information on the subject. One of those is a MatLab solution from which you might be able to extract the required formulas, provided the license allows, which I haven't checked.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
First you need to translate the longitude and latitude to your center "camera point".
Then you need to use a projection such as equidistant projection to get the X & Y.
Everything you need C# wise is in System.Math just be aware of degrees/radians. If you have degrees coordinates you have to convert to radians first. Trigonometry sites should have the other formulas you need
|
|
|
|
|
You want to do a projection of a sphere to a flat sheet of paper.
In order to minimize projections errors, the projection formula is different for every place in the world.
A common technique is to do the projection on a cone.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
You mean you want the x, y pixel coordinate?
That should be simple math.
- Remember that your "map image" has a x,y coordinate of 0,0 in the top, left and the max_x, max_y on the bottom, right (AKA the Y-axis points down!). The max_x and max_y coordinate is the width and heiht of your bitmap respectively.
- Look up the coordinate of the top left corner. That is equal to the 0,0 x,y coordinate. Same for the bottom right.
- From that point, it is just converting the coordinate system to the x,y coordinate system. It is easier to treat the degrees/minutes/seconds as a double variable, but you should find it on google easily to convert from one format to the other. I would recommend the "rule of three" to calculate the x,y or the degrees (depending on your needs):
77 degrees = 100 pixels //in this example : the difference between the left and the right for the horizontal values
0,77 degrees = 1 pixel
28,49 degrees = 37 pixels (for example)
so if you start out left with let's say 25 degrees, moving 37 pixels adds 28,49 degrees.
//you do the same for y coordinate
I hope that was of some help (and that was indeed your question)
|
|
|
|
|
Hi, i have a file i am reading a file as
bytes[] fileData = File.ReadAllBytes("fileName");
now i would like to read 0 to 19 bytes from fileData and write it to one file and then 20 to 39 to another file, like this i have to read till end and write it to different files.
Can any one help me to do this.
thanks in advance....
|
|
|
|
|
|
You're just reading 20 byte offsets here. A simple loop taking the offset into account would do that. It's fairly straightforward - you have the maximum possible number of bytes already, from your File.ReadAllBytes. From this, it is trivial to calculate how many iterations you would need to read 20 byte chunks (just divide the total number by 20 - as a test, can you figure out whether you need to add anything to this value for any remaining bytes - this should test whether you understand integer division in C#). Then, for each iteration, read 20 bytes - except for the last iteration, that might actually be less bytes if your file isn't easily divisible by 20. I have given you all the hints you need in this description to work out how to do this.
This space for rent
|
|
|
|
|
Pete O'Hanlon wrote: I have given you all the hints you need in this description to work out how to do this. But.. but where is the codez!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
May be you have to work a little.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|