471,321 Members | 1,662 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

accessing data in external file?

Hello,

Just starting C# with MS Visual Studio Pro 2005 ...

How do I access array data which is in an external file? I would
prefer to have it there to make the code less cluttered..

Thanks

Geoff
Jan 13 '06 #1
4 1765
Geoff,

How are you storing the data in the file? Can you provide a sample of
the file?

The first recommendation would be to use the FileStream class to open
the file for reading. Once you have that, you can use the BinaryReader
class to read primary type information from the file (assuming you wrote the
file in a format that the BinaryReader can understand).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Geoff Cox" <ge*******@remove-this.freeuk.com> wrote in message
news:pr********************************@4ax.com...
Hello,

Just starting C# with MS Visual Studio Pro 2005 ...

How do I access array data which is in an external file? I would
prefer to have it there to make the code less cluttered..

Thanks

Geoff

Jan 13 '06 #2
On Fri, 13 Jan 2006 10:40:13 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
Geoff,

How are you storing the data in the file? Can you provide a sample of
the file?
Nicholas,

The idea is to have a series of statements, the left hand side and the
right hand side statements, for each of several situations, eg

var lhs_0 = new Array(8)
lhs_0[0]="situation 1 lhs statement 1";
lhs_0[1]="situation 1 lhs statement 2";
etc

var rhs_0 = new Array(8)
rhs_0[0]="situation 1 rhs statement 1";
rhs_0[1]="situation 1 rhs statement 2";
etc

var lhs_1 = new Array(8)
lhs_1[0]="situation 2 lhs statement 1";
lhs_1[1]="situation 2 lhs statement 2";
etc

var rhs_1 = new Array(8)
rhs_1[0]="situation 2 rhs statement 1";
rhs_1[1]="situation 2 rhs statement 2";
etc

Cheers

Geoff



The first recommendation would be to use the FileStream class to open
the file for reading. Once you have that, you can use the BinaryReader
class to read primary type information from the file (assuming you wrote the
file in a format that the BinaryReader can understand).

Hope this helps.


Jan 13 '06 #3
Geoff,
the "var" keyword doesn't come out until C# 3.0, so we can only assume that
this is Javascript. How about storing your data in some sort of CSV format
with delimiters which would be easier to parse?
Or, you could make the array a member of a serializable class, serialize the
class to a byte array using the BinaryFormatter class, and save it as a
binary file. This would be much easier to read back and deserialize into the
class.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Geoff Cox" wrote:
On Fri, 13 Jan 2006 10:40:13 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
Geoff,

How are you storing the data in the file? Can you provide a sample of
the file?


Nicholas,

The idea is to have a series of statements, the left hand side and the
right hand side statements, for each of several situations, eg

var lhs_0 = new Array(8)
lhs_0[0]="situation 1 lhs statement 1";
lhs_0[1]="situation 1 lhs statement 2";
etc

var rhs_0 = new Array(8)
rhs_0[0]="situation 1 rhs statement 1";
rhs_0[1]="situation 1 rhs statement 2";
etc

var lhs_1 = new Array(8)
lhs_1[0]="situation 2 lhs statement 1";
lhs_1[1]="situation 2 lhs statement 2";
etc

var rhs_1 = new Array(8)
rhs_1[0]="situation 2 rhs statement 1";
rhs_1[1]="situation 2 rhs statement 2";
etc

Cheers

Geoff



The first recommendation would be to use the FileStream class to open
the file for reading. Once you have that, you can use the BinaryReader
class to read primary type information from the file (assuming you wrote the
file in a format that the BinaryReader can understand).

Hope this helps.


Jan 13 '06 #4
On Fri, 13 Jan 2006 09:50:02 -0800, "Peter Bromberg [C# MVP]"
<pb*******@yahoo.nospammin.com> wrote:
Geoff,
the "var" keyword doesn't come out until C# 3.0, so we can only assume that
this is Javascript. How about storing your data in some sort of CSV format
with delimiters which would be easier to parse?
Peter,

Yes, you are correct, I am trying to make a C# version of some
javascript code. At the time I could not find a slider control. I was
using Visual Web Developer 2005 Express at that time.
Or, you could make the array a member of a serializable class, serialize the
class to a byte array using the BinaryFormatter class, and save it as a
binary file. This would be much easier to read back and deserialize into the
class.


Could you point me at info re how to make the array a member of a
serializable class etc?

Cheers

Geoff

Jan 13 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by ShepardBerry | last post: by
4 posts views Thread by Eugen Walcher | last post: by
3 posts views Thread by Frederick Gotham | last post: by
21 posts views Thread by Hallvard B Furuseth | last post: by

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.