|
As the only difference in coding is to keep references to the objects created, it doesn't matter how large the objects are. The size of a reference is always the same.
When optimizing code it's very useful to know what the code really does, in order to find out what code is worth optimizing, and how.
Example:
int a = 42;
string y = a + "," + a;
That looks simple, but can be written much more efficient in this more lengthy way:
int a = 42;
string x = a.ToString();
string y = x + "," + x;
The first code will be executed something like:
int a = 42;
string y = string.Concat(Number.FormatInt32((int)new Object(a), null, NumberFormatInfo.GetInstance(null)), (string)(object)",", Number.FormatInt32((int)new Object(a), null, NumberFormatInfo.GetInstance(null)));
while the second code will be executed as:
int a = 42;
string x = Number.FormatInt32(a, null, NumberFormatInfo.GetInstance(null));
string y = string.Concat(x, ",", x);
---
b { font-weight: normal; }
|
|
|
|
|
The latter seems to be faster, is this correct?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Probably a half second faster over the span of 1 million calls to it. But, of course, your milage may vary depending on your machine and how you drive it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi,
a very simple question:
when i create an windows application in VS the starting point is usually the form.
i would like my base class as a starting point (having the MAIN method) from which i start the gui. how do i do it?
when i simply do:
MyGUI gui = new MyGUI();
gui.Show();
the gui does not show for long.
regards,
rnv
|
|
|
|
|
Application.Run(new MyGUI()) should be enough
|
|
|
|
|
If MyGUI is a form then try with Application.Run(new MyGUI());
|
|
|
|
|
|
Hi everybody! I'm buliding a little Database where I have to insert Data through a mask made with some TextBox form and TextLable form.
Can I bind a dataset to this kind of forms? How can I make possible to show in the boxes the selected row of the dataset?
Do the Framework implements this functionality?
Thank you!
|
|
|
|
|
Why can't I install and start a service using the following code?
<br />
private void Test()<br />
{<br />
try<br />
{<br />
Process p = Process.Start(@"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\regsvcs", @"/fc C:\My.dll");<br />
p.WaitForExit();<br />
if(p.ExitCode != 0)<br />
{ <br />
Console.WriteLine("My service install(RegSvcs) failed!!!");<br />
Console.WriteLine("ExitCode was: "+p.ExitCode);<br />
return;<br />
}<br />
ServiceController sc = new ServiceController("My",Environment.MachineName);<br />
sc.Start();<br />
Console.WriteLine("My service started!");<br />
}<br />
catch(Exception ex)<br />
{<br />
Console.WriteLine("Install failed - Exception!!!");<br />
Console.WriteLine(ex.ToString());<br />
}<br />
}<br />
RegSvcs works fine and the service places itself in the COM+ services (I can see it via the ServiceComponents app), but when the code reaches sc.Start(), it throws an Exception with the following information:
System.InvalidOperationException.
Service My was not found on computer 'MBU'.
InnerException = System.ComponentModel.Win32Exception
(Danish)Den angivne tjeneste findes ikke som en installeret tjeneste
(Translated)The service does not exists as an installed service
Has it something to do with the service being a DLL and not an EXE and therefore you can't start it with a ServiceController?
I can start it manually, by using the Componentservices app and right click on the "My" service.
That means the service works, but just can't be started by the above shown code.
What is going on?
|
|
|
|
|
As for as I know Services must be installed with a Setup Project to work corectly. I never used services, and I am not sure about this, just try it anyway.
|
|
|
|
|
That is actually what I am trying , but I need a CustomInstall event to fire AfterInstall in order to start the service - but it doesn't.
I'm in the high-fidelity first class traveling set.
And I think I need a Lear jet.
|
|
|
|
|
Bad english - it does fire the afterinstall event.
It is the sc.start() call that doesn't work.
|
|
|
|
|
How Can I Call Operator in The following example
namespace A
{
public static MyClass operator <=(MyClass f1, MyClass f2)
{....}
}
and I want to call it from another class ???
|
|
|
|
|
Not sure what you are asking...
If have operator <= overloaded for MyClass, you can use it for MyClass. as in
MyClass a,b;
if (a <= b) .....
If you want to do something like
YourClass a,b;
if (a <= b) .....
you would have to do it again for YourClass.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Is there a way to display different context menus(or with different submenus) for a treee view for different nodes. Foe example if i have too roots and I want to display a different menu for the child nodes of the forst root, other than for the children of the seccond root.
I have tryed with after select or mouse up event but I want also to retrieve the selected node that generated the menu but it does`n works.
|
|
|
|
|
Here's code snippet that shows different context menus for selected tree node.
private void Form1_Load(object sender, System.EventArgs e)
{
// create the root node
TreeNode treeNodeRoot = new TreeNode("Root");
treeNodeRoot.Tag = "root";
// create first child node
TreeNode treeNodeChild1 = new TreeNode("Child1");
treeNodeChild1.Tag = "child";
treeNodeRoot.Nodes.Add( treeNodeChild1 );
// create second child node
TreeNode treeNodeChild2 = new TreeNode("Child2");
treeNodeChild2.Tag = "child";
treeNodeRoot.Nodes.Add( treeNodeChild2 );
treeView1.Nodes.Add( treeNodeRoot );
}
///
/// Create context menu
///
/// <param name="tag" />tag value
/// <returns>
private ContextMenu GetContextMenuByTag(string tag)
{
ContextMenu contextMenu = new ContextMenu();
if( tag.StartsWith("child") )
{
contextMenu.MenuItems.Add("Child menu item");
}
else
{
contextMenu.MenuItems.Add("Root menu item");
}
return contextMenu;
}
private void treeView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button==MouseButtons.Right)
{
// retrive node or use treeView1.SelectedNode
TreeNode theNode= treeView1.GetNodeAt(e.X, e.Y);
if (theNode!=null)
{
if( theNode.Tag!=null )
{
ContextMenu contextMenu =
GetContextMenuByTag((string)theNode.Tag);
contextMenu.Show( treeView1, new Point(e.X, e.Y) );
}
}
}
}
DevIntelligence.com - My blog for .Net Developers
-- modified at 3:16 Monday 9th January, 2006
|
|
|
|
|
Subscribe to the MouseDown event of the Treeview control. In the event handler, code it like
if (e.Button == MouseButtons.Right)
{
Point point = new Point(e.X, e.Y);
TreeNode node = treeView.GetNodeAt(point);
if (node == null)
return;
treeView.SelectedNode = node;
if (node.Tag is TypeX)
{
XContextMenu.Show(treeView, point);
}
else if (node.Tag is TypeY)
{
YContextMenu.Show(treeView, point);
}
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thx I didn`t knew about the treeView1.GetNodeAt method
|
|
|
|
|
Dear all,
I have developed a .NET dll. I wants to use this dll in Win32(Delphi) applications. Is it possible to do the same.
The data type of arguments passed to the functions in the dll & returned from it are compatible. The return type is a byte array & the arguments passed are string. But, when i used this dll in a Win32 application(developed using Delphi), EAccessViolation exception occurs.
Can anyone suggest me how to use the .net dll in win32 applications?
Thanks & regards,
Abhilash
|
|
|
|
|
|
Clickety Cops[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Delphi is COM based, so you have to write your .DLL to expose its properties and methods to COM. You can find documentation on what you need to do here[^].
For a bit more friendly discussion, see the link the other poster gave you.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 9:23 Monday 9th January, 2006
|
|
|
|
|
i tried creating the tlb of the dll. The is created, But again the application gives the same exception. Whether we have to include this tlb also in the delphi(pascal) application? How can i acheieve that. At present i am declaring the functions in the dll in application & using it.
Also, when we deploy the application & install it in a target PC, whether it will take care of the registration of the dll in the target PC also. Means, when we run the setup of the application, it must handle all the issues.
If i go for a COM+ component, whether i can achieve the same?
Thanks & Regards,
Abhilash
|
|
|
|
|
i have no idea why that exception is being thrown. There's only about a thousand different causes. Try posting the code where the Exception is thrown.
You have to take care of building a Setup project for your application, including any .DLL's it uses and their registration. Since your using a C# class library in your Delphi app, you also have to make sure that the .NET Framework is installed so the .DLL can be loaded and used.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi, is there a way to run other applications within my application? For example, run Internet Explorer and Firefox in my application in separate tabs.
Thank you.
KiT
|
|
|
|