Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I was told that ReadToEnd() was slower than if you put the whole thing into a byte[] and went from there. I think I am having problems, because my method is so much slower than ReadToEnd() is:

 

public static object Read(ref string path)
	{
		string g="";
		if(File.Exists(path))
		{
			Stream F=new FileStream(path, FileMode.Open, FileAccess.Read);
			byte[]b=new Byte[F.Length];
			F.Read(b, 0, Convert.ToInt32(F.Length));

			for(int i=0; i< b.Length; i++)
			{
				if(b[i]==0) break;
				g+=(char)b[i];
			}
		//StreamReader s=new StreamReader(path);
		//string g= s.ReadToEnd();
		//s.Close();
MessageBox.Show(g);
			F.Close();
		}
		return g;
	}

 

Why is mine so slow?

Edited by divil
C#
  • *Experts*
Posted

Yes, you can put "using System.Text.Encoding" at the top and call "ASCII.GetString()".

 

-Ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...