|
If you want to have all the data in memory, then yes, you'd have 5000 instances of this class.
You could, for example, add a static function to your class FromString() to perform parsing of a single input line and return a new instance holding the correct values.
This instance would then be added to your collection.
Something like this:
MyClassCollection coll = new MyClassCollection();
while((text_line = tr.ReadLine()) != null)
{
MyClass cls = MyClass.FromString(text_line);
coll.Add(cls);
} Regards,
mav
|
|
|
|
|
Something like this:
FileStream fs = new FileStream(_sFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
StreamReader reader = new StreamReader(fs);
ArrayList dates = new ArrayList();
ArrayList data = new ArrayList();
char[] sep = {','};
while(reader.Peek() != -1)
{
string[] rec = reader.ReadLine().Split(sep);
double[] record = new double[rec.Length];
for(int i = 0; i < rec.Length; i++)
{
if(Char.IsLetter(rec[i],0))
record[i] = 0d;
else
{
try
{
record[i] = double.Parse(rec[i]);
}
catch
{
record[i] = 0d;
}
}
}
data.Add(record);
}
double[][] dData = (double[][])data.ToArray(typeof(double[]));
reader.Close();
fs.Close();
reader = null;
fs = null;
|
|
|
|
|
Anthony,
EXCELLENT! 10/10. When it is presented as code it make things so much clearer. It is good to see how other people use the c# language. Your short piece of code has given me extra ideas how to use C#.
Thanks you for your effort it is appreciated.
Thanks,
Liam
|
|
|
|
|
hi all,
I need to send an Email with attached document to pub1234@yahoo.com .I have to do it using C# coding.
How I do it?.
Can any one help me ?
thanks in advance..
|
|
|
|
|
This question has been asked here a gazillion times, so please use the search function before posting...
Regards,
mav
|
|
|
|
|
Hi
I save my documents in a database. While opening them, I make a copy on the local hd and open them. But how can I know, when the user has finished with the changes and closed the document, so I can save them back to the db?
Is there something like a file open check?
At least the office programms have kind of a lock, so only one user can open the document. Can I use that - and if yes, how?
Thank you
Adrian
|
|
|
|
|
Hi!
There's no general "data from this file still in use" flag.
As long as a file has been opened by an application, Windows will know that the file is open, but usually an application will close the file as soon as it's been read. While you're working with the data, the file is closed, so there's no general way to know when you've finished manipulating the data.
Each application has to decide for itself if and how to maintain file locks.
For Office documents there might be properties to find out the user who has opened a document recently, but I'm not sure.
For other documents each application will most likely behave differently.
Regards,
mav
|
|
|
|
|
I can think of following workaround
Create a copy of your current file in memory, then try to delete it, (see MSDN File.Delete Function) if it throws the IOException, the file is still in use .
if it's deleted, write your in-memory version to db.
Good luck.
No hurries, no worries.
|
|
|
|
|
That won't work!
Imagine a plain text file that's being edited with Notepad.
The file will only be in use while Notepad actually loads it. This takes a fraction of a second, after that your "workaround" would save the file back to the DB, albeit the user didn't even have a chance to modify the text or save the changed file!
mav
|
|
|
|
|
Im checking a workaround by watching the process I had started. It doesn't work always, because most of the programs, like word, don't create a new process when they'r already open.
|
|
|
|
|
ok tnx, but there should be a way for checking if a file is in use, no?
No hurries, no worries.
|
|
|
|
|
There is a check, and usually the easiest way to check is to try to open a file exclusively. If this fails, then usually another process has the file in use.
But the main point is that "file is in use" is not the same as "the data inside the file is being modified".
mav
|
|
|
|
|
The process watcher version doesn't work neither. The problem is, that many programs immediately delecate the file to another process and stop the first one. By office programs I even never get the process.
|
|
|
|
|
That's what I'm saying. There is no general way, sorry.
mav
|
|
|
|
|
|
Hello,
is it possible to use datagrid component of .net 2005 in .net 2003?
if yes, please tell me how??
|
|
|
|
|
The short answer is No, that DataGrid requires 2005 to run. The 2003 compilers will not work with the 2005 .NET Framework. You'd have to write a remoting wrapper around the DataGrid class. The more I think about it, the uglier it gets.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello Everyone:
I have posted the same question in managed C++ board.
This is my problem:
I have C# project compiled as a DLL. The C# class is defined as:
public Cs_Class
{
String name;
public Cs_Class(String n)
{ name = n; }
....
}
I have another MC++ project that uses the DLL. The MC++ class is defined as:
public Cpp_Class
{
....
void Test(String* testStr)
{
//Create the c# class
//
Cs_Class* c = new Cs_Class(testStr);
}
}
The compilation/linking was fine. I then encountered a run-time exception:
System.MissingMethodException: Method not found: Cs_Class..ctor(System.String)...
Strangly enough, if I took out the String parameter in Cs_Class constructor and not pass in String* in MC++ class when constructing the Cs_Class object, then everything was fine.
Why??
Thanks in advance.
David
|
|
|
|
|
To hence forth the problem is to dematerialize the occasion of being interpeticular of yomessing
|
|
|
|
|
I'm not a native english speaker either, but this seems to come from a translation program and has completely lost its meaning in the process of translation.
Am I correct? And if I am, which translation service was used and what was the original phrase?
:->
mav
|
|
|
|
|
Hello,
I am not sure I understand what you meant here. Can you explain your point in plain English? Thanks
|
|
|
|
|
I want to compile a existing c# class file, inside another program. I used the Following code. But it does not give any outputs. can you tell me a correct way to do this. thanks.
Process pr = new Process();
pr.StartInfo.FileName = "csc.exe";
string filePath = "D:\\Dilan Projects\\Application3\\LabelWriter.cs";
pr.StartInfo.Arguments ="/out:cl_labelservice.dll /t:library " + filePath;
pr.Start();
this code not working.
|
|
|
|
|
'not working' is kind of enigmatic. What's going wrong ? Best guess - you need to specify a path to csc.exe
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Do you see a console window opening up? Did you try redirecting standard output and error to see what's actually going on?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Have you taken a look at the ICodeCompiler interface or the CSharpCodeProvider class?
They offer services to compile code on the fly without having to find out where the compiler actually lives.
Regards,
mav
|
|
|
|