473,385 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ToString -> upper and lower

I am getting Guid using

new Guid()

when I say

new Guid().ToString() I get 10856f25-2759-0358-159c-ff7e0759c800

but when I say

new Guid().ToString().ToUpper() I get following

D98C1DD4-008F-04B2-E980-0998ECF8427E

what is going on?
Nov 17 '05 #1
13 2953
Firstly, if you create a guid with empty constructor "new Guid()" you should
get only zeros...
I believe you are using System.Guid.NewGuid(), and everytime you run this
you are supposed to get a unique guid... so they will always be differrent.

HTH,

Erick Sgarbi
www.blog.csharpbox.com
I am getting Guid using

new Guid()

when I say

new Guid().ToString() I get 10856f25-2759-0358-159c-ff7e0759c800

but when I say

new Guid().ToString().ToUpper() I get following

D98C1DD4-008F-04B2-E980-0998ECF8427E

what is going on?

Nov 17 '05 #2
I should have paste the code. Anyways, all this time I was trying to find
the reason and it is as following after that code

System.IO.FileInfo fi = new System.IO.FileInfo(@"C:\h.html");
Stream fs = fi.Open(FileMode.Open,FileAccess.Read,FileShare.No ne);
MD5 hash = new MD5CryptoServiceProvider();
byte[] b = hash.ComputeHash(fs);
byte[] a = hash.ComputeHash(fs);

This code calls ComputeHash on fs 2 times. Both time I get different byte
array.

Is it cause ComputeHash is not reading the file till the end and calculates
the hash code on what ever is read the first time and then second time it
reads rest of the buffer and recalculates?

What I am doing wrong?
<no***********@csharpbox.com> wrote in message
news:9d************************@msnews.microsoft.c om...
Firstly, if you create a guid with empty constructor "new Guid()" you
should get only zeros... I believe you are using System.Guid.NewGuid(),
and everytime you run this you are supposed to get a unique guid... so
they will always be differrent.

HTH,

Erick Sgarbi
www.blog.csharpbox.com
I am getting Guid using

new Guid()

when I say

new Guid().ToString() I get 10856f25-2759-0358-159c-ff7e0759c800

but when I say

new Guid().ToString().ToUpper() I get following

D98C1DD4-008F-04B2-E980-0998ECF8427E

what is going on?


Nov 17 '05 #3
I have a test code that shows ComputeHash read to the end of the
stream: in the following code you can see b is the same with c, you can
try d,e,f,g,.... and it will be the same value of b & c.

static void WriteBytes(byte[] bytes)
{
foreach (byte b in bytes)
{
Console.Write(b.ToString() + " ");
}
Console.WriteLine();
}

static void Main(String[] args)
{
System.IO.FileInfo fi = new System.IO.FileInfo(@"d:\test\test.txt");
Stream fs = fi.Open(FileMode.Open, FileAccess.Read, FileShare.None);
MD5 hash = new MD5CryptoServiceProvider();
byte[] a = hash.ComputeHash(fs);
Console.WriteLine(fs.Position.ToString() + " ?= " +
fs.Length.ToString());
byte[] b = hash.ComputeHash(fs);
byte[] c = hash.ComputeHash(fs);

WriteBytes(a);
WriteBytes(b);
WriteBytes(c);
Console.ReadLine();
}

Nov 17 '05 #4
RealFun,

Yes I know position is eq to length but a and b are not same. Again, in my
original problem, I am not getting the same value for a and b.

b, c, d,... are same and that is ^not^ what I am asking.

thanks,
Po
<re*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I have a test code that shows ComputeHash read to the end of the
stream: in the following code you can see b is the same with c, you can
try d,e,f,g,.... and it will be the same value of b & c.

static void WriteBytes(byte[] bytes)
{
foreach (byte b in bytes)
{
Console.Write(b.ToString() + " ");
}
Console.WriteLine();
}

static void Main(String[] args)
{
System.IO.FileInfo fi = new System.IO.FileInfo(@"d:\test\test.txt");
Stream fs = fi.Open(FileMode.Open, FileAccess.Read, FileShare.None);
MD5 hash = new MD5CryptoServiceProvider();
byte[] a = hash.ComputeHash(fs);
Console.WriteLine(fs.Position.ToString() + " ?= " +
fs.Length.ToString());
byte[] b = hash.ComputeHash(fs);
byte[] c = hash.ComputeHash(fs);

WriteBytes(a);
WriteBytes(b);
WriteBytes(c);
Console.ReadLine();
}

Nov 17 '05 #5
I got affused puzzled about what is your question

Nov 17 '05 #6
I got puzzled about what is your question

Nov 17 '05 #7
Pohihihi <po******@hotmail.com> wrote:
I should have paste the code. Anyways, all this time I was trying to find
the reason and it is as following after that code

System.IO.FileInfo fi = new System.IO.FileInfo(@"C:\h.html");
Stream fs = fi.Open(FileMode.Open,FileAccess.Read,FileShare.No ne);
MD5 hash = new MD5CryptoServiceProvider();
byte[] b = hash.ComputeHash(fs);
byte[] a = hash.ComputeHash(fs);

This code calls ComputeHash on fs 2 times. Both time I get different byte
array.


Yes, I'm not surprised - you're reading the whole file in first, so b
gets a proper hash, but then you're reading using the same stream,
which has already finished - so a is the hash of nothing, basically.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #8
Jon Skeet [ C# MVP ],
woo...he said it's not his question

Nov 17 '05 #9
Thanks Jon, you gave me the reason I was looking for.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Pohihihi <po******@hotmail.com> wrote:
I should have paste the code. Anyways, all this time I was trying to find
the reason and it is as following after that code

System.IO.FileInfo fi = new System.IO.FileInfo(@"C:\h.html");
Stream fs = fi.Open(FileMode.Open,FileAccess.Read,FileShare.No ne);
MD5 hash = new MD5CryptoServiceProvider();
byte[] b = hash.ComputeHash(fs);
byte[] a = hash.ComputeHash(fs);

This code calls ComputeHash on fs 2 times. Both time I get different byte
array.


Yes, I'm not surprised - you're reading the whole file in first, so b
gets a proper hash, but then you're reading using the same stream,
which has already finished - so a is the hash of nothing, basically.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #10
re*****@gmail.com <re*****@gmail.com> wrote:
Jon Skeet [ C# MVP ],
woo...he said it's not his question


Where, exactly? It looked like his question really was about why a and
b are not the same, and that was what I answered...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #11
hehe
I have just said "I have a test code that shows ComputeHash read to the
end of the stream"
and he replied that is not about the quetion, so i think perhaps he is
asking about other things

:)

Nov 17 '05 #12
re*****@gmail.com <re*****@gmail.com> wrote:
hehe
I have just said "I have a test code that shows ComputeHash read to the
end of the stream"
and he replied that is not about the quetion, so i think perhaps he is
asking about other things


Evidently not, given his other reply. I think the problem was that
while you understood what the problem was, your reply didn't make it
obvious to him.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #13
ok...
i learned a lot from you and thanks for your patient

Nov 17 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: BBFrost | last post by:
I'm receiving decimal values from database queries and placing them on a report page. The users want to see the following .... Db Value Display Value 123.3400 123.34...
6
by: Joe | last post by:
Stupid question, but I'm really stuck I have a class that overrides ToString(). When this class is cast back to Object, and ToString() called, Object.ToString() is called instead. I've tried...
8
by: John Cobb | last post by:
Excuse me if I use some terminology incorrectly as I am not well versed in Object Orientation. In short I want to create an Enumerated type similar to the following Enum Monitor as Byte Small...
0
by: bcobra | last post by:
What am I doing wrong? the code: age Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls"...
7
by: Dylan Parry | last post by:
Hi folks, I was wondering if there is any way of formatting a date to include the ordinal characters? I've looked at the documentation for DateTime.ToString(), but no where can I find...
2
by: archana | last post by:
Hi all, I am facing some wired problem while using above mention data type. What i am doing is i am writing DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" +...
1
by: ivansh | last post by:
Hello, For one java class (Hello) i use another (HelloPrinter) to build the string representation of the first one. When i've tried to use this from within jython, HelloPrinter.toString(hello)...
8
by: Phil Jollans | last post by:
Hi, I am having difficulty overriding the ToString() method of CultureInfo using Visual Studio 2005. Exactly the same code works fine with Visual Studio .NET 2003. What I am doing is adding...
2
by: Berryl Hesh | last post by:
I'm interested in how experienced.Net developers might handle routine display tasks as a general strategy. Let's say you have a use in your domain for value objects that encapsulate a person's...
19
by: Michael C | last post by:
If we have something like this object x = null; MessageBox.Show(x.ToString()) we get an error. That kindof makes sense but there is no reason the behaviour couldn't be to return an empty...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.