|
hi
I want to be able to do the following:
Type mytype = MethodInfoArray[i].GetParameters()[0].GetType();<br />
mytype[] p = new mytype[5];
Is that possible?
cheers
|
|
|
|
|
You are looking for Array.CreateInstance[^]. You can use it like
Type mytype = MethodInfoArray[i].GetParameters()[0].GetType();
Array a = Array.CreateInstance(myType, 5);
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thank you ... that worked great ... but I should hae explained
The bacis problem I have is this:
Type requiredtype = getType();<br />
Object[] datafrominputs = getData();<br />
MethodInfoArray.Invoke(new Object(),new Object[]{datafrominputs});
Basically the method will take a single array as its parameter, but I need to be able to convert may Object array to the right type. What should I do?
cheers
-- modified at 7:30 Monday 29th May, 2006
|
|
|
|
|
|
Yeah I have but I get:
InvalidCastException: "Object must implement IConvertable"
I was trying to convert from an Object[] to an int[].
cheers
|
|
|
|
|
Did you call Convert.ChangeType on the array itself or did you loop through the array and call it for each element in the array? I think the first approach won't work.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
y that's an idea... when looping through I would have to store the array in type determined at runtime (using the array class, I think). How could I then pass that as a parameter?
thanks for all the help
|
|
|
|
|
Try this piece of code
static Array ConvertArray(object[] arr, Type type)
{
Array a = Array.CreateInstance(type, arr.Length);
for (int i = 0; i<arr.Length; ++i)
{
a.SetValue(Convert.ChangeType(arr[i], type), i);
}
return a;
}
Regards
Senthil
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
i want to develop a menu and form based Add-in for MS outlook. i have found some material but was unable to get the real way for visual studio.net can anyone please help me actually i want the complete process from developing to deploying.
Tahnks and regards
|
|
|
|
|
hello,
i have opened the txt file in the rich text box but i could not opened the doc file or pdf extension file in rich text box.
please help me to sort this out by writing some code or giving me the links of the site.
a .net programmer
|
|
|
|
|
Performacne(Speed) wise which one is best among For loop and foreach
Jey
|
|
|
|
|
They exist to service different needs. However, in some situations you can use both. for(int i=0; i<array.Length; i++) is faster for iterating over an array, but then you have to do more work as you have to extract the values out of the array manually.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
-- modified at 4:34 Monday 29th May, 2006
|
|
|
|
|
Actually, Brad Abrams here[^] says that for arrays, for and foreach generate identical code for iteration.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Interesting - I've never check the MSIL but I've seen performance stats on code that suggest the for() is faster than foreach() for arrays - I guess it was talking about ArrayList and I didn't pick up on that.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Hi all,
How do i send more than one command to command prompt through C#. I know how to send one command at a time but i need to send two. One needs to change my current directory path from: c:\Documents and settings to: c:\program files\progressive projects\progress\reports\reporttemplates here i need to run a batch file but this part i know...
ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe");
// /c switch sends a command
startInfo.Arguments = "/C " + command;
// redirect messages to this program
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
//don't execute using shellexecute API
startInfo.UseShellExecute = false;
//Don't open command prompt window
startInfo.CreateNoWindow = true;
System.Diagnostics.Process p = System.Diagnostics.Process.Start(startInfo);
string output = p.StandardOutput.ReadToEnd();
string error = p.StandardError.ReadToEnd();
p.WaitForExit();
if (output.Length != 0)
shellControl1.WriteText(output);
else if (error.Length != 0)
shellControl1.WriteText(error);
thank you in advance
He who laughs last...
|
|
|
|
|
You could send a batch file that does everything that you want. Or you could redirect standard input and push the commands to the input stream (I've never tried that so I'm only guessing that it would work)
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
huh????
im quite new to this... Be gentle
He who laughs last...
|
|
|
|
|
My two suggestions expanded:
1. You are calling cmd.exe and sending it a command to execute. Instead of wondering how to send it more than one command, why not put all your commands in a batch file and send cmd.exe the batch file to execute
2. Call cmd.exe and redirect the StandardInput. You can then write commands to the cmd.exe process as if you were typing on the command prompt itself. (However, I've never tried this so I can't say with 100% certainty that it will work or be without problems)
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
okay thanks, i'll give it a shot
He who laughs last...
|
|
|
|
|
after filtering dataview, when i retrive the dataview by a loop. i get the orginal dataview contents. but if i use it as a datasource of a datagrid then i can found the filtered data.plz fix the problem...
|
|
|
|
|
try the following code
int i=0;
IEnumerator ienm = dtv.GetEnumerator();
while(ienm.MoveNext())
{
MessageBox.Show(dtv[i].Row["column name"].ToString());
i++;
}
here dtv is filtered dataview
rahul
-- modified at 5:21 Monday 29th May, 2006
|
|
|
|
|
thanks for ur help. but now i want to put this values of dataview in a datatable.but how i can not do it. cause i am new in c#.plz help me...
|
|
|
|
|
i m new in c#.
working in this topic.
but i don't know from where and how to start.
plz help me or give initial comment!
alok
-- modified at 4:23 Monday 29th May, 2006
|
|
|
|
|
What kind of file is that (.msg) ?
If that file is a binary file, you can read it using BinaryReader and write it to text again using StreamWriter.
|
|
|
|