|
Hi. I am coding a program (important: .NET 2 (3.5), C#) where i get input of GUIDs in various formats. On MSDN is documented, that it is possible to use
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
or zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz
or {zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz}
or (zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz)
or {0xzzzzzzzz, 0xzzzz, 0xzzzz,0xzz,0xzz,0xzz,0xzz,0xzz,0xzz,0xzz,0xzz}} The goal is to produce a (hex)string of length 32 characters (for 16 bytes) regardless of input.
So I programmed and debugged and tested and looked ...
System.Guid test=new System.Guid("{2426186D-B96D-4656-9B65-15C727744643}");
System.Console.WriteLine(BitConverter.ToString(test.ToByteArray()).Replace("-", string.Empty));
What goes wrong? I expect to see "2426186DB96D46569B6515C727744643", but get
"6D1826246DB956469B6515C727744643". Please give advice. TIA Nicki.
|
|
|
|
|
Make sure the result from "ToByteArray()" is what you expect it to be.
Put that operation on a separate line, and place a breakpoint so you can examine the resulting byte array.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
?test.ToString();
"2426186d-b96d-4656-9b65-15c727744643"
byte[] bytes=test.ToByteArray();
{byte[16]}
[0]: 109
[1]: 24
[2]: 38
[3]: 36
[4]: 109
[5]: 185
[6]: 86
[7]: 70
[8]: 155
[9]: 101
[10]: 21
[11]: 199
[12]: 39
[13]: 116
[14]: 70
[15]: 67 ... and the byte order is messed
|
|
|
|
|
So can you use test.ToString()?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Yes,
?test.ToString().Replace("-",string.Empty);
"2426186db96d46569b6515c727744643"
will fit my needs. So this will be the permanent workaround as solution. But the (IMHO) missbehavior with .ToByteArray() will remain. THX anyway, Nicki.
|
|
|
|
|
It' not misbehaving. It's doing exactly what it should be doing. ToByteArray is not setup to return an array of bytes to YOUR liking. It's setup to return an array of bytes that can be used to quickly build another Guid object.
Internally, the GUID value is not stored as an array of bytes, but as individual fields of various types, combining to form a single GUID. These types include Int32, Short and Byte.
What you think is misbehavior is the correct representation of a 32-bit integer and of a Short and of individual bytes.
|
|
|
|
|
|
Why don't you use "test.ToString()"?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Quick Test in Immediate Window:
Guid test=new Guid("{2426186D-B96D-4656-9B65-15C727744643}");
{2426186d-b96d-4656-9b65-15c727744643}
_a: 606476397
_b: -18067
_c: 18006
_d: 155
_e: 101
_f: 21
_g: 199
_h: 39
_i: 116
_j: 70
_k: 67
?test.ToString();
"2426186d-b96d-4656-9b65-15c727744643"
|
|
|
|
|
I want to create a table "Employee" with columns:empname,age and empcode(which takes two letters from employee name and append number to it.,e.g.:-ga1,om2 where ga stands for ganesh,om stands for omkar)
please help me with the following
|
|
|
|
|
It's already in the C# forum; please don't cross-post.
FWIW, sounds like a calculated field to me.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Where are you stuck?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Take the first two characters of one name and concatenate to the other.
|
|
|
|
|
Hello, my 2nd post here, so I'm a bit of a nOOb.
AFAIK the convention for using Radio Buttons is to have 1 selected by default.
Q: Is it reasonable or acceptable to break this convention for the purpose of forcing the user to make a deliberate selection in a customised application?
B/ground: I made the buttons myself using Small Basic and they are for a Pizza order form. One group has 2 sets of buttons, 1 set [small, medium, large], 2nd set [thin, thick]. The user can only continue once selection is made.
Currently I'm thinking why not by considering that a convention is a wise and preferred norm as opposed to a rule which may not allow such discretion. Also I read that some API's allow the use of RB's without having 1 selected by default.
|
|
|
|
|
Sure, I don't see why that wouldn't be acceptable. It is a practice used many places. As an example, on the CodeProject main page, there is a new survey every week and when it is the type that requires a radio button input, none of the options are initially selected.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Thanks Soren for your helpful reply.
Wow I just realised it is xmas on the other side of the planet. Happy xmas.
Yeah I think conventions are contextual. 'When in CodeProjectLand do as CodeProjectarians do'.
|
|
|
|
|
Jibba Jabba wrote: Yeah I think conventions are contextual. 'When in CodeProjectLand do as CodeProjectarians do'. I wouldn't say that, I see that behavior all the time, referring to the CP survey just seemed like an obvious thing to do.
Jibba Jabba wrote: Wow I just realised it is xmas on the other side of the planet. Happy xmas. Merry Christmas to you too.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
"I wouldn't say that, I see that behavior all the time, referring to the CP survey just seemed like an obvious thing to do."
Thanks, helpful reply. And I agree.
In my solution to the exercise, not only was it obvious, I stated (on the other forum) that the hypothetical pizza shop owner wanted it. Happy user? That's gotta be good.
Appreciate your experience and thoughts.
|
|
|
|
|
I see it both ways many times. It all depends on what your needs are. If you want to force a selection then don't have one selected by default.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Thanks for your replies.
I just found the vote helpful button. Was a bit slow, nOOb issues.
|
|
|
|
|
You're welcome.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Just adding some more thoughts on this.
If an api required a default selection based on this said convention, and you chose not to make your own buttons, then applying this to the pizza example, I'd have to have a default "no selection" choice, which is redundant and I think absurd. And then force an alternative selection.
Unusual convention I think. Once again thanks for your thoughts on this.
|
|
|
|
|
How to start working with asp.net web application
|
|
|
|
|
Get a book and start working through the examples. The do some online tutorials, then define the project you want to do and find some examples and tutorials on or close to the subject.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
In addition to Mycroft's suggestion, you could also go to http://www.asp.net/[^]. Also note that there is a specific forum for ASP.NET questions.
Veni, vidi, abiit domum
|
|
|
|