|
according to this specification i think your code is incorrect. you should do something like that, i am just providing a pseudo code.
static string [] methodlist;
static int currentmethod;
main()
{
}
function X()
{
while(!allmethodscompleted)
{
for calling function from name check out this
<a href = "http://www.codeproject.com/csharp/delegates_and_reflection.asp" rel="nofollow">http:
}
}
Regards
Shajeel
|
|
|
|
|
I want to access child forms save method through mdi toolbar save button.
how can i acesss that method runtime.
because when i call active from's save method it gives me error method or member not define.
Hallo
|
|
|
|
|
you can do parent form's method as public and then
on your chid form
<br />
frmParent frm = new frmParent();<br />
frm.MypublicMethod();<br />
i hope that it is ok for u!
|
|
|
|
|
I think he wants to access a child's method from a parent.
he should do the same as u said but with the child form

|
|
|
|
|
ooppps but the result is same
|
|
|
|
|
yea sure it is the same.
i just posted that for the thread poster to take attention to it.
good job anyways
|
|
|
|
|
Hi,
Its Ok!But i want to decide at runtime which child forms method will run.
Suppose
Form1 is mdi and Form2/from3.... is child;
Form2/form3..... contains save() mehod;
i want active forms save() method
like
Form f=new Form2(); ///Form2 is Currently Active..
f.save();
like
Hallo
|
|
|
|
|
vaibhavnvag wrote: Form f=new Form2(); ///Form2 is Currently Active..
Unless Form is not the base Form class, but one that you defined to use polymorphically, the problem here is that although f is a Form2, you only *know* it's a Form. You need to use reflection, or cast the variable to the right type, before you can see methods that are only on the derived class.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello,
First you should build a base Form (BasicForm) from where your Form2 and Form3 inherit.
If save() method in Form2 and Form3 are different:
This BasicForm has than a virtual method save() which is overriden in Form2 and Form3.
If its the same functionality in both forms, you just have to make the method once in BasicForm.
Then in Form1 code you could do:
BasicForm activeForm= this.ActiveMdiChild as BasicForm;
if(activeForm!=null)
{
activeForm.save();
}
Hope that helps!
All the best,
Martin
|
|
|
|
|
Ok! Thank!!!!
My problem is solved.....
Hallo
|
|
|
|
|
I want this statement valid in C#:
Integer i = 0;
In C/C++ you can easily do it by define an alias name for it, for example
#define Integer Int32
But you can not do it in C#. So what should I do?
Thank you for your reading.
|
|
|
|
|
using Integer = System.Int32;
...
Integer i = 0;
Keep in mind that the C# int keyword is an alias for System.Int32.
|
|
|
|
|
|
hey Judah, thanks from me too!
i thought aliasing we can do only for namespaces!!
|
|
|
|
|
No, you can alias types, too. There is one caveat: unlike C/C++, aliases are per-file. Each file that wants to use the Integer alias described above would have to have to specify it in using declarations.
They are especially useful with generics, IMO.
using IntStringPair = System.Collections.Generic.KeyValuePair<int, string>;
...
List<IntStringPair> listOfPairs = ...;
|
|
|
|
|
Judah Himango wrote: using IntStringPair = System.Collections.Generic.KeyValuePair<int, string="">;
That's a shame, I hated when people did that in C++....
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Heh, well, at least it's limited in scope. It's true, I always hate having to track down aliases in C++. Or worse, aliases of aliases of aliases...etc. I don't think you can do alias an alias in C#, which is good.
Question is, is the aliasing worth it? Which one would you rather encounter:
List<KeyValuePair<int, string>> listOfPairs = new List<KeyValuePair<int, string>>();
foreach(KeyValuePair<int, string> pair in listOfPairs)
{
...
}
or
using IntStringPair = System.Collections.Generic.KeyValuePair<int, string>;
...
List<IntStringPair> listOfPairs = new List<IntStringPair>();
foreach(IntStringPair pair in listOfPairs)
{
...
}
|
|
|
|
|
I'd prefer the former, because there's no question of what it is. Actually, I would create a struct that names the int and string according to what they represent.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Interesting. I'd prefer the latter because it is descriptive enough by its name alone and it's easier on the eyes than the double generic type. But, I do see where you're coming from. Aliases are certainly open to abuse, albeit on a much smaller level than C++ #defines. Come to think of it, I can't say I've seen alias abuse in any project I've worked on, especially nothing so terrible as abominations like A Better C[^] or VB++[^].
|
|
|
|
|
I've worked on C++ projects where I was always going back to see what the typedefs meant. I hated it.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I agree with Chris. I've dealt with C++ projects where the developer went crazy with typedefs. Even though C# has a similar ability, it is much simpler to use the native data type names. They may not be as short as we want or as clear within the specific application domain, but they are unambigous and standard. I don't have to worry about a new developer trying to understand what an IntStringPair is, or look for it on MSDN. KeyValuePair<int, string> clearly defines the object using terms that everyone is familar with.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Christian Graus wrote: That's a shame, I hated when people did that in C++....
I think they are useful, since you haven't to interpretate again and again complex expressions.
Anyway it's a matter of taste.
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.
|
|
|
|
|
Christian Graus wrote: That's a shame, I hated when people did that in C++....
That depends how! With a define or a typedef?
|
|
|
|
|
I have a block of code like the following
sqlConnection1.Open();
using (SqlDataReader reader = mySqlQuery.ExecuteReader())
{
//use reader here
}
sqlConnection1.Close();
my question is, with reader inside a using block, reader.Close() is automatically called once execution goes out of the using block scope. do I have to call sqlConnection1.Close() then?
also if an exception occurs, do I have to put my sqlConnection1.Close() inside a finally block, if the call is actually necessary?
Thanks in advance!
|
|
|
|
|
To be safe you can do like this
using(sqlConnection1 = new SqlConnection())
{
sqlConnection1.Open();
using (SqlDataReader reader = mySqlQuery.ExecuteReader())
{
}
sqlConnection1.Close();
}
You can also do this:
sqlConnection1.Open();
using (SqlDataReader reader = mySqlQuery.ExecuteReader(CommandBehavior.CloseConnection))
{
}
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
|
|
|
|