|
"Input string was not in a correct format."
You are trying to convert a value that can not be interpreted as a number.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
I have a control array and have tested the control type to find a listview. I want to assign the control to a listview with something like below.
System.Windows.Forms.ListView olistview = new ListView();
olistview = g_control_array[i];
C# does not like this and i get a cannot convert control to listview. Is there a way to achieve this as I can't find anything to help do this.
The only othe way I can think of is to establish an array of listviews as well but i would prefer not to do this unless I have to.
Thanks for any help.
Stephen
|
|
|
|
|
You want to read a ListView out of the control array?
Then you won't have to create a new one. The control array can contain any control, so you have to tell the compiler "I'm sure this item is a ListView":
ListView olistview;
olistview = (ListView)g_control_array[i];
|
|
|
|
|
Worked. Thanks.
Too easy!
Stephen
|
|
|
|
|
Hi
I've got the following code:
I get the error: The node to be inserted is from a different document context.
I've already imported the, so whats wrong?
XmlNode toNode(string input)
{
XmlDocument a = new XmlDocument();
a.LoadXml(input);
return a.DocumentElement;
}
XmlNode tmp = toNode("<string></string>");
lines[linenumber].ImportNode(tmp, true);
lines[linenumber].AppendChild(tmp);
cheers
|
|
|
|
|
The ImportNode methods returns the node.
---
b { font-weight: normal; }
|
|
|
|
|
Howdy all,
I have a problem in trying to get application domains setup and hope somebody there could point me in the right direction. I came across code from gotdotnet that is called apploader (http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=2C78AB99-E190-4A4A-A91A-F7DE1DE78E5B[^]. I am trying to implement a Windows Forms that creates an application domain, using the SpawnedApp class as per in the source for apploader, load the process into the newly created appdomain. Funny thing is this, in the AppLoader as per gotdotnet.com it's Main Thread attribute is [MTAThread], Winforms are by default [STAThread], Apploader worked a treat - loaded assemblies fine and worked, but I've tried to get it to work under winforms which fails. It loads the assemblies under the newly created appdomain on a winform and executes up to a certain point then it crashes. Is there something I'm missing or something that is not well documented regarding creating app domains in a winforms application?? Would threading have anything to do with it as that's my hunch. I click on a button which fires a thread, then creating a new instance of spawnedapp class with the full path to the assemblies/config file which in turn creates a thread and executes it in the new appdomain.
I've been tearing my hair out in frustration .Maybe my sig sums it all up!!
Hope you could help me out on this one!
Kind regards,
Tom Brennan.
#define STOOPID
#if STOOPID
Console.WriteLine("I'm stoopid!");
#endif
|
|
|
|
|
|
Hi Nick, Tom here, I have an application that has a lot of assemblies, and from the console AppLoader, it loads all the assemblies fine. It is from a WinForm Application that it loads partial assemblies then it keels over and dies with threadabort exception...The reason I wish to load it into an app domain is one of security. I was using the SpawnedApp Class from the AppLoader...
Thanks Nick for your reply!
Tom Brennan.
#define STOOPID
#if STOOPID
Console.WriteLine("I'm stoopid!");
#endif
|
|
|
|
|
Hi again Nick, Sorry for not replying sooner. This is interesting, the reason the Winforms that instantiated the class SpawnedApp in a new application domain failed was becuase I had an Application Wide Exception Handler for trapping unhandled exceptions. I removed the offending line and it worked. Strange!! That was the thing I noticed with the AppLoader code - it didn't have the application wide exception handler so I'm wondering why? AppDomain didn't obviously like it and no wonder it keeled over and died upon loading the app in that new appdomain. So take this tip if you're having problems with AppDomains....Am currently investigating in the MS-KB to see if that's a documented behaviour or a bug.....
Thanks again Nick for your help!
Kind Regards,
Tom Brennan.
#define STOOPID
#if STOOPID
Console.WriteLine("I'm stoopid!");
#endif
|
|
|
|
|
Hi fellows
I'm studying C# and I've seen the StructLayoutAttribute class. In their description was written this:
"The StructLayoutAttribute class allows the user to control the physical layout of data fields of a class or structure".
I've seen the LayoutKind enumerator too. This was written in their description: "Control the layout of an object when exporting to unmanaged code".
There are three options:
Auto, which the runtime chooses the appropriate layout for the members of an object.
Explicit: which the precise position ( how? precise position?) of each member of object in unmanaged memory is controlled.
Sequential: which the members of object are laid out sequentially, in order that they appear whn exported to unmanaged code.
I didn't understand nothing. What want it to say when it says "control the physical layout" of a class?
Thanks for help guys
|
|
|
|
|
That is where each member is placed in the memory area that is reserved for the object or structure.
AFAIK, by default the members are arranged for fastest memory access, e.g. padded to place them on an even address boundary.
---
b { font-weight: normal; }
|
|
|
|
|
hello,
Can anyone recommend one or two C# articles on CodeProject which you think has very good/professional code, is well-documented, uses good design, follows .NET coding guidelines, etc.
I'm looking for some examples of well written and complete classes/controls/etc that I can learn from to improve my own code.
|
|
|
|
|
Search for Marc Clifton's articles. Sometimes it can be confused in the beginning cause Marc understand a lot of C#, but if you read paying attention, the Marc's articles are great. There are a lot of great article writers, I prefer Marc.
Another good article writer is Xiangyang Liu.
I like of their styles, they are very professional in their articles. It's my opinion.
|
|
|
|
|
Thanks Alex,
I'll take a look at those articles...
|
|
|
|
|
Hi,
Please clarify which is more efficient.
using string.Empty or "". If so please explain why is this.
Iam often getting confused on this.
Thanks.
|
|
|
|
|
Hi!
Using "" will be marginally faster because the runtime doesn't have to look up a constant, but I strongly doubt that you will notice a difference in real life.
But I think it's more important to keep an eye on good readability than to try and tune execution speed by replacing string.Empty with "".
Regards,
mav
|
|
|
|
|
But both string.Empty and "" will be constants. The only difference is where they are declared. The constant for string.Empty already exists, so there are hardly any point of creating more constants that are identical.
---
b { font-weight: normal; }
|
|
|
|
|
Not entirely correct, I think. I looked it up in IL.
Using the constant
string.Empty
compiles to
ldsfld string [mscorlib]System.String::Empty
whereas using
""
yields
ldstr ""
So I'd assume the runtime would have to check at least once whether mscorlib is loaded already (which is, of course) to be able to access a constant defined in a type from this assembly.
Using "" doesn't require this lookup, so it should be _a wee little bit_ faster, but, as I wrote, I don't think you'll be able to notice it.
Regards,
mav
|
|
|
|
|
mav.northwind wrote:
Using "" doesn't require this lookup, so it should be _a wee little bit_ faster,
Here is the optimized JIT code. Same thing... except with "" you will be adding more strings to the string table of the assembly.
16: string a = "";
0000000f mov eax,dword ptr ds:[01AA1010h]
00000015 mov esi,eax
17: string b = string.Empty;
00000017 mov eax,dword ptr ds:[01AA2014h]
0000001c mov edi,eax
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
|
|
|
|
|
I expected it to be very little difference in the compiled code, but I didn't expect it to be as good as no difference at all.
Anyway, regardless of how it is currently implemented, the code that best resembles your intention will often be the most efficient. The compiler will be able to optimize the code better if the information you give it is better. In some future implementation or on a different system, using string.Empty might even be the most efficient way.
---
b { font-weight: normal; }
|
|
|
|
|
mav.northwind wrote:
Using "" will be marginally faster because the runtime doesn't have to look up a constant, but I strongly doubt that you will notice a difference in real life.
If you look at the difference in the IL, string.Empty almost sounds faster.
ldstr ""
vs.
ldsfld string [mscorlib]System.String::Empty
With ldstr , it's pushing an object reference to a string literal stored in the metabase onto the stack where as ldsfld pushes the value of a static field onto the stack.
mav.northwind wrote:
But I think it's more important to keep an eye on good readability than to try and tune execution speed by replacing string.Empty with "".
I completely agree.
|
|
|
|
|
On a related note, if you're checking to see whether a string is empty, it is more efficient to use
if(str.Length == 0)
instead of
if(str == "") or if(str == string.Empty)
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
|
Hi everybody.
I open a Word document in the web browser control, I then select some text in it using a mouse, and I want to paste the selected text into another text box on the same form, but it does not work.
The code looks like this:
Clipboard.SetDataObject("");
_web.Focus();
_web.ExecWB(SHDocVw.OLECMDID.OLECMDID_COPY, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,ref refmissing , ref refmissing);
IDataObject iData = Clipboard.GetDataObject();
if(iData.GetDataPresent(DataFormats.Text))
{
textBox2.Text = (String)iData.GetData(DataFormats.Text);
}
It is as if the selected text gets copied somewhere else. I did an extensive search on the web, but to no avail.
Sending keys to the browser control will get no results, like:
_web.Focus();
SendKeys.Send("^c");
Nothing in the clipboard aftert that operation either.
Thanks a lot.
Sarajevo, Bosnia
|
|
|
|