|
1. I'm not sure I understand the question. What difference does it make? Perhaps you should ask this in a separate thread away from the context of this question on exceptions. Somebody else might understand better.
2. For more precise control over the serialisation, for custom serialisation formats and schemas. Which you might need if you are planning on serialising the object for interop with another system.
Simon
|
|
|
|
|
|
Hello George,
pertaining to your first question,
[Serializable] attribute is used for serialization as well as deserilization.
your second question leads to a microsoft answer of serializing only few public members of a class not all the public members . Just for an example if you are having a class Employee
Class Employee
{
public string name;
public int empid;
public int salary;
}
by making it [serializable] ,will serialize all public members of Employee class
Suppose you don't want to serialize salary .....then what you will do ?
The solution given by microsoft:-
Implement ISerializable interface and override two function and serialize what ever public member you want to serialize.
vijay
|
|
|
|
|
Adding to what others said, don't derive from ApplicationException . Derive from Exception instead.
|
|
|
|
|
I agree, thanks!
regards,
George
|
|
|
|
|
I have a textfile with values separated by tabs. It looks like below (only difference is that there can be many more columns and rows):
Voltage Temperature
6.41000 4.76610
3.41000 4.76366
6.41000 4.83936
6.41000 5.00298
6.41000 5.01763
6.41000 5.05670
Can anyone suggest a method to read from the text file and put the values in a matrix???
The problem is that nothing is known from the beginning. I was thinking of using ReadLine() and then break up the line in smaller pieces (one piece per value) but I find it hard to do because of all the unknown parameters (number of characters in each value, number of columns in the text file etc.)
Thanks!
|
|
|
|
|
If you know the character that will separate columns, you can use ReadLine() method and than use Split() method of string class. There are several libraries at codeproject that can help you in reading csv files.
|
|
|
|
|
Hello everyone,
How can I convert a byte array to string?
It works:
string text = Encoding.ASCII.GetString(byteArray);
But what should I do if I don't know the encoding of my byte array? Should I read bytes one by one and create string?
Thank you.
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
You have to know the encoding... what if it is unicode? (2 bytes for 1 char)...
|
|
|
|
|
V. wrote: You have to know the encoding
But... OK, is there any simple way to find the encoding of a text?
I found this article[^], it works fine but it's too complex.
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
There is no simple way that can handle any encoding.
Where do you get the byte array from in the first place? Why is it that you don't know how the text was encoded?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: Where do you get the byte array from in the first place?
void ReadFile(string filePath, long length)
{
string text;
using (FileStream fsReader = new FileStream(filePath, FileMode.Open, FileAccess.Read)
{
byte[] byteArray = new byte[length];
fsRead.Read(byteArray, 0, length);
}
RTB.Text = text;
}
Guffa wrote: Why is it that you don't know how the text was encoded?
User can open any files (*.*)
--A non-related question: Are non-text files (*.exe, *.mp3, *.avi, ...) have any encoding?--
Guffa wrote: There is no simple way that can handle any encoding.
Thanks a lot. It seems I should use that article[^] to get the file encoding, no problem
Thank you again.
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
Pedram Behroozi wrote: fsRead.Read(byteArray, 0, length);
That doesn't work properly. The Read method returns the number of bytes that was actually read, and that may be less than the bytes requested. If you ignore the return value, you may get a partly read file and an array full of garbage.
You can use the File.ReadAllBytes method to read the file:
byte[] byteArray = File.ReadAllBytes(filePath);
Pedram Behroozi wrote: Are non-text files (*.exe, *.mp3, *.avi, ...) have any encoding?
No. As they are not text that is encoded into bytes, they don't have any encoding.
Part of the files may contain data that is encoded text, though. An mp3 file can for example contain an id3 block that contains text.
Pedram Behroozi wrote: It seems I should use that article[^] to get the file encoding
No, that article is about selecing an encoding to use to encode a text, not determining how text was encoded.
To determine the encoding you should start by looking for a BOM (byte order mark) at the beginning of the file. If there is one, it's a unicode file, and you can determine the encoding from the BOM. Otherwise it's either an ASCII or ANSI file. You should look for bytes with a value above 127 to determine what special characters are used and try to guess the encoding from which characters you expect there to be. If there are no codes above 127 you can use the ASCII encoding to decode the file.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Oh, you helped me a lot. A million Thanks Guffa
[Edit]
I read your reply over 5 times, really nice explain. Thank you again.
When you're alone in the Dark, Fear will protect you...
modified on Wednesday, November 12, 2008 12:12 PM
|
|
|
|
|
5ed!
I am surprised to see the depth of your knowledge. You are great.
Guffa wrote:
To determine the encoding you should start by looking for a BOM (byte order mark) at the beginning of the file. If there is one, it's a unicode file, and you can determine the encoding from the BOM. Otherwise it's either an ASCII or ANSI file. You should look for bytes with a value above 127 to determine what special characters are used and try to guess the encoding from which characters you expect there to be. If there are no codes above 127 you can use the ASCII encoding to decode the file.
Where can I learn such kind of things? Is there a webpage or books available?
|
|
|
|
|
I want to show the text from a ListView subitem in a ToolTip when the user puts the mouse over a row.
I have:
void diaryListView_MouseMove(object sender, MouseEventArgs e)
{
ListViewHitTestInfo lvhti;
lvhti = diaryListView.HitTest(e.X, e.Y);
if (lvhti.Item != null)
{
ListViewItem item = diaryListView.GetItemAt(e.X, e.Y);
string notesText = item.SubItems["Notes"].Text;
}
}
but I have the error "Object reference not set to an instance of an object" for the line: string notesText = item.SubItems["Notes"].Text;
What should I have done to correct this please?
|
|
|
|
|
Firstly, why are you doing ListViewItem item = diaryListView.GetItemAt(e.X, e.Y); ? Can't you just use lvhti.Item ?
The error means that an object you are trying to use is null.
Item could possible by null, (although I suspect that is unlikely because you did a hit test first, and checked that for null).
More likely is that the item does not have a sub item called notes.
if (lvhti.Item != null)
{
if (lvhti.Item.SubItems.ContainsKey("Notes"))
{
String notesText = notesItem = lvhti.Item.SubItems["Notes"].Text;
}
} You should check that the subitem you are looking for exists first.
Simon
|
|
|
|
|
Many thanks for your reply Simon. I've referenced the SubItem by index, rather than name, and it works fine. Although I'm not sure why referencing it by its name does not work.
|
|
|
|
|
Check that you have got the name exactly correct including the correct case. Check you are setting the key correctly when you create the subitem.
(If it's still not working, post the code where you create the items and sub items)
Simon
|
|
|
|
|
Hi,
I've created a borderless form which is custom located at point(0,0) (the top of the desktop).
the form size is; height: 26px, width = screen width.
my case is when I open another application (i.e. msWord) the top of the msWord window (Title, Grabbing aria, close, min, max buttons) is hidden behind my topmost form.
How can I setup my form to act like the taskbar; which will not allow the new application window to load behind the bar?
tnx
|
|
|
|
|
leeoze wrote: How can I setup my form to act like the taskbar; which will not allow the new application window to load behind the bar?
You need to register your application as an AppBar for this to happen. See this[^] MSDN article and this[^] CP article.
/ravi
|
|
|
|
|
hi,
I have made an application in which i am recording phone call using voice modem in my personal computer,now i want to make answering machine like in call center ,ex.. press 1 for change language. press 2 for recharge like that any idea???
Thank's
jugal
|
|
|
|
|
Modern telephones use Dual-tone multi-frequency (DTMF)[^] signals to represent the numbers.
You need to play your message "Press 1 for this, Press 2 for that" and then listen to the incoming signal. You need to processes the signal and determine the low frequency portion and the high frequency portion. You can then determine the number (Keypad[^])
(You should also make sure you handle the case that the user doesn't have a DTMF telephone. There are other methods like pulse dialling, which are rarely used any more, but probably still exist. Just have a default selection if no tones are detected)
Simon
|
|
|
|
|
I want to get the row index when I hover a datagrid.
I use the mousehover event but can't seem to get the row index since I want to get the rowindex even if the actual row has not been clicked.
Any help appreciated.
|
|
|
|
|
Im using a tool by sysinternals that shows me whether a file has a signature and the date it was signed. However, I need the api for C#, so that i can get the same results.
Atm I use cmd sigcheck send the results it to a stream and parse the results, but if i have 1000s of files I need to process.start cmd 1000s of times.
Any help is appreciated.
|
|
|
|