|
yeah, you're right. So, when the static constructor first throws an exception, any attempt to use the static methods (or maybe instance methods) rethrows the exception.
I never use static constructors, and such behavior does not make me want to them.
|
|
|
|
|
I think the TestStatic.SaySomething will not be called and it will directly go to the catch block.
But the second TestStatic.SaySomething will be called because static constructors are called only once, afaik.
Am I correct ?
|
|
|
|
|
erm... No. But well done for not cheating.
Regards,
Rob Philpott.
|
|
|
|
|
So, both me and this guy give the correct answer. You greet him and you accuse me of cheating. You're a plain a**hole.
|
|
|
|
|
You both got the answer wrong . He was only joking when he asked if you were cheating...
|
|
|
|
|
He forgot the icon, so I took as a personal attack.
|
|
|
|
|
That's a bit rude isn't it? Not sure I like you. And neither did I accuse you of cheating. Tut.
Regards,
Rob Philpott.
|
|
|
|
|
Hmmm I am not sure of this.... Anyway, my apologies if I offended you.
|
|
|
|
|
Not offended at all Sir.
Regards,
Rob Philpott.
|
|
|
|
|
I didnt think you could compile with a static constructor? I assume i am wrong thou as others have tested? so in which case i would say output is..
HI
Hi 2
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Can't compile with a static constructor?! Not sure they'd be much use in the language if that were the case. Sorry, you're wrong too.
Regards,
Rob Philpott.
|
|
|
|
|
hmmm... well as the TestStatic class is not static it can have a constructor, i just didnt know it could be static. but either way any static methods (i.e. SaySomething) can be called without the need to create an instance of your class, which you are not doing in your code. So both calls to the SaySomething method should be successful, can you explain why either would fail? i think not.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Any class can have a static constructor, but it is highly recommended to make sure they never throw exceptions.
|
|
|
|
|
musefan wrote: i think not
Really, what is wrong with you people? I think so as described below.
Regards,
Rob Philpott.
|
|
|
|
|
what about...
Afternoon Exception
HI
Hi 2
edit: no, that wouldnt happen if an exception is thrown when the program runs then surely it would just crash with the unhandled exception in the static constructor, no?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Ok, well, you have a static ctor which will throw an exception the first time the type is used, so it would be:
Afternoon Exception
Hi 2
Correct?
|
|
|
|
|
Nope!
Regards,
Rob Philpott.
|
|
|
|
|
Ok, I rethought.
The ctor fails, and that is bad.
How about
Afternoon Exception
Afternoon Exception
?
|
|
|
|
|
Good man! And we have a winner. Yep, the type initialiser fails both times - in short an exception in a static constructor is very bad news.
Well done.
Regards,
Rob Philpott.
|
|
|
|
|
I ran your code for the fun of it, and although the exception message is output twice, the type initializer only fails once, as far as the debugger can tell.
|
|
|
|
|
Congratz! =)
(Shame on me, SHAME ON ME!)
|
|
|
|
|
Hey guys, I have a simple question to with I haven't been able to find a clear answer !
I want to to get ID of a row that I select ! (not row ID, the value of ID column)!
Could u help me out please !
Mr.K
|
|
|
|
|
Event: DataGrid1_MouseDown or DataGrid1_MouseUp
method: Grid1.Rows[0].Columns[0].Value.ToString()==""
ok,understand? so easy ,my english is not very good ,so i can only do my best to help u
|
|
|
|
|
Firstly you need to make it clear if it is a DataGrid or a DataGridView that you are using. They are two different controls, and which one you are using will make a difference to the answer.
I am going to give you an answer based on two assumptions, that it is in fact a DataGridView , and the Column is called 'ID'.
Assuming that you can identify the row selected, hint - research DataGridView.CurrentRow , and have it assigned to a field:DataGridViewRow selectedRow = dataGridView1.CurrentRow .
string idString = selectedRow.Cells["ID"].Value.ToString();
The Point about the two types of grid is important, otherwise you get no answers, or worse you spend ages following a totally wrong answer.
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanx all the guys who helped me out !!!
finally with ur help found it out !
DataGridViewRow SelectedRow = new DataGridViewRow();
SelectedRow = GrammarGrid.CurrentRow;
SelectedGrammarID = Convert.ToInt32(SelectedRow.Cells["GrammarID"].Value);
|
|
|
|