I've readed a few articles on stackoverflow but i couldn't figure out how to do it. I've made a small code for reading mixed\binary files (making a new one, with separated methods, the older one was messed) - but i'm in doubt on how to call the method on the program's main.
I figured out i should instantiate each variable before using them on the method's call - but how do i do that with string ? I know this is a newbie question but i'm new to c# - also i've searched over stackoverflow and other places and couldn't find an suitable answer.
Thanks.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;
namespace ConsoleApplication2
{
class Program
{
public void FileOpen(ref OpenFileDialog of, ref string filename, ref int nfiles)
{
of.Filter = "PPF Files | *.ppf";
of.Multiselect = true;
of.ShowDialog();
filename = of.FileName;
nfiles = of.FileNames.Count();
}
public void FileRead(ref OpenFileDialog of, ref string filename, ref List<string> freaded, ref int nfiles, ref string filecontents)
{
string aux;
List<string> filesreaded = new List<string>();
if (string.IsNullOrEmpty(of.FileName) == false)
{
for(int i=0; i<nfiles; i++)
{
// Read the file into <bits>
using (var fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
{
var len = (int)fs.Length;
var bits = new byte[len];
fs.Read(bits, 0, len);
// Dump 16 bytes per line
for (int ix = 0; ix < len; ix += 16)
{
var cnt = Math.Min(16, len - ix);
var line = new byte[cnt];
Array.Copy(bits, ix, line, 0, cnt);
// Convert non - ascii characters to .
for (int jx = 0; jx < cnt; ++jx)
{
if (line[jx] < 0x20 || line[jx] > 0x7f)
line[jx] = (byte)'.';
}
aux = Encoding.ASCII.GetString(line);
filecontents += aux;
}
}//Closing FileStream
}//Closing files loop (operations for each file)
}//Closing IF Statement
}//Closing FileRead function
[STAThread]
static void Main(string[] args)
{
Program a = new Program();
OpenFileDialog openf = new OpenFileDialog();
int filenumber = new int();
string fullfilename //What to do here?
//How can i instantiate a new string so i can use it when calling the method ?
a.FileOpen(ref openf , ref fullfilename , ref filenumber);
}
}
}