|
|
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
|
|
|
|
|
I typed it in invisible text.
This space for rent
|
|
|
|
|
A memorymapped file is what you want as per by the book
Memory-mapped files are beneficial for scenarios where a relatively small portion (view) of a considerably larger file needs to be accessed repeatedly.
Using Memory-Mapped Files[^]
In vino veritas
|
|
|
|
|
Once you read the file to a byte array, you just need a loop that take chunks of 20 bytes at the time.
Rather basic !
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
I know that the code snippet below is equal, but which is better?
Sample sm = new Sample()
{
prop1 = 1,
prop2 = 2
};
and
Sample sm = new Sample();
sm.prop1 = 1;
sm.prop2 = 2;
Is there any advantage and disadvantage on both of them?
what's your thought about this?
thanks
|
|
|
|
|