|
|
Uhh, every method needs memory to execute.
Having said that, a static method does not need memory to be allocated for an object (aka instance) to be executed; as opposed to a non-static method.
Cheers,
Vikram.
"If a trend is truly global, then that trend ought to be visible across ANY subset of that data" - fat_boy
|
|
|
|
|
Is it possible to throw an exception in any of the drag/drop events? Whenever I try to throw one (on purpose) code execution returns at the point of the exception, but no exception dialog appears and my application doesn't halt.
Is something interceding on my behalf because throwing an exception in any of these events is a bad move, or is this a bug of some sort?
VS2008 Pro/C#3.0/.Net 3.5/Vista x64.
PS Dragging stuff from a different domain (Outlook) on to my app.
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
Hi all,
I have two datatables.
dt1 has the columns: nr, name, address, tel, mobile, fax
dt2 has the columns: name, address, mobile
How can i make from those two datatable one datatable? i have to set the result later in a datagrid.
thanx.
|
|
|
|
|
Just make a third table that has the columns of the other two in it. You can pull the column names out of the two tables and insert them into the third. Populate the third with the data and bind the third table to the datagrid. It's easy, just involves a couple steps.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi Paul, thanx for your response.
how do i populate the third datatable with the data of dt1 and dt2???
can u write some code pls?
|
|
|
|
|
|
Giorgi,
Thanx a lot, it realy helped
|
|
|
|
|
You are welcome
|
|
|
|
|
I'd just do a select that joins the two tables on name, or if you do that often enough, create a view that does it. Don't do it in memory, get the database to do what it's good at.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
let's assume this...
bt is a Button;
<br />
bt.Click += delegate( object sender, EventArgs e )<br />
{<br />
MessageBox.Show( "something" );<br />
};<br />
I also know that we can do this:
<br />
string s = "something";<br />
bt.Click += delegate( object sender, EventArgs e )<br />
{<br />
MessageBox.Show( s );<br />
};<br />
But.. what if I wanted to put inside the delegate some code that is stored in a string?
like...
<br />
string code ="MessageBox.Show( \"something\" );";<br />
bt.Click += delegate( object sender, EventArgs e )<br />
{<br />
??? code ????<br />
};<br />
is there anyway one can do something similar to this? I thought of reflection, but... the context would be missing. Any thoughts? thanks...
Gonçalo A.
|
|
|
|
|
No you can't use a string for the body of the delegate. If you need to take different actions when the button is clicked, then create a handler and branch the code accordingly.
only two letters away from being an asset
|
|
|
|
|
Even though... if I create an EventHandler, I'll still have the same problem. If the inner code is coming from another source, I still don't have a way to "reflect" that code. Am I right?
Thanks for the reply, btw
Gonçalo A.
|
|
|
|
|
So, if I understand correctly, you have an object, call it B, who has the code (in string format) to run when some event in object A is fired, right? I don't understand why you can't have obj B simply add an event listener to the event of obj A. It sounds like you want to dynamically run some annonymous code from B that you won't know until runtime, but if at runtime you know the code, then why can't you just do A.Click += new ClickEventHandler(B.DoWhatever);? If this is not what you need (or want), then please explain a bit more on why exactly you need to have the php exec command in C#.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Well, the thing is, the code I do want to run, is not something I know. It's something I retrieve at runtime, let's say, from a file. I open a file, read the content, and then, have an event to run that content. That is what I want, so I can't have a B.DoWhatever function. I know this is something awkward to want... but this would be what I need. Any thoughts?
Thank you for the reply
Gonçalo A.
|
|
|
|
|
Although as a programmer this approach appears to make sense to you (you are loading source code into a dynamic method), to the computer the approach does not make sense as the source code you are loading is not compiled. In order to achieve this, you would have to load the source code then compile it at run-time and then execute it most likely using reflection ;->
|
|
|
|
|
Those were my thoughts exactly, that I was stuck with reflection. Though, the context is a problem... I cannot fit the code in the context that I want.
Anyways, thank you for the replies.
Gonçalo A.
|
|
|
|
|
Ahhhh, now I understand. Do you have control over the code in the file, or is it a third party thing that you don't want to edit? If you have control, why not make the code a class with a method that does the work for you? For example, if you want to take in a string a return a boolean, make a static class "Container" with the method "public static bool DoWork(string input)". Does this help at all? I think the problem is you are trying to modify the running dll at run-time, which sounds like it is not possible (without hacked code and a lot of work). You need to branch to new code, execute it, then return, which is exactly what functions are for. Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Yes, I kind of wanted something very weird, I said it. But it's only logical that it's not possible. That would mean to alter a dll in runtime... The decision I came up to go around this is using reflection. I send in a sort of a sandbox with variables that I might want to alter in the code, fetch the code from the file, encapsulate it inside a neat namespace with a class and a method, compile it, and run it. Seems to do the trick. I had to create a few "syntax hacks" to access the sandbox, like...
<br />
$var as Label.Text = "something";<br />
and in runtime replace the "pretty" line into something more ugly to access the sandbox. It works, and does the job very well.
I also needed to create two more "syntax hacks" in case I need an extra reference, or to use an extra namespace that is not included by default in the assembly chunk.
<br />
#assembly "System.Drawing.dll";<br />
#using System.IO;<br />
Those three "hacks" are not very elegant, but... it allows me to have this done in a very generic way, which, in the current project, is the only way.
Thank you all for the replies... and... if anyone as any thoughts on this, please let me know.
Gonçalo A.
|
|
|
|
|
Hello.
I am new to c#.
When I am coding like this (I dont know whether it is right or wrong)
if (this.ColorGrade ="31-1" || this.ColorGrade="31-2" || this.ColorGrade="31-3")
{this.QGrd='F';}
I m getting the subject message.
What should I do?
|
|
|
|
|
Use == for comparision:
if (this.ColorGrade =="31-1" || this.ColorGrade=="31-2" || this.ColorGrade=="31-3")
this.QGrd='F';
As you can se you dont ha to include { and } when the if-line is followed by one statement only.
|
|
|
|
|
Viktor Nilsson wrote: As you can se you dont ha to include { and } when the if-line is followed by one statement only.
You're correct. Now, what does it have to do with the question that was asked?
only two letters away from being an asset
|
|
|
|
|
It is the
"if isn't needed then drop it"
school.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Viktor Nilsson wrote: As you can se you dont ha to include { and } when the if-line is followed by one statement only.
That is a matter of programming style. For readability, I always include the brackets:
if (this.ColorGrade == "31-1" || this.ColorGrade == "31-2" || this.ColorGrade == "31-3") {
this.QGrd='F';
}
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Guffa wrote: For readability, I always include the brackets:
Ditto me. Mind you, I hate the use of this.ColorGrade in the test. I'm not that enamoured of using this. . Note - I know this wasn't your code, so I'm not having a go here, merely stating my dislike.
|
|
|
|