This is a question in the matter of speed. I have the following code:
if (MyXMLReader.SearchForValue(command, new List<string>() { "/Command/Descriptions/Description/System" }, ((TabDocument)dockManager.ActiveDocument).version))
{
txtBox_desc.Text = MyXMLReader.GetValue(command, "/Command/Descriptions/Description[" + MyXMLReader.SearchForValue_Int(command, new List<string>() { "/Command/Descriptions/Description/System" }, ((TabDocument)dockManager.ActiveDocument).version) + "]/Content");
}
if (MyXMLReader.SearchForValue(command, new List<string>() { "/Command/Uses/Use/System" }, ((TabDocument)dockManager.ActiveDocument).version))
{
txtBox_use.Text = MyXMLReader.GetValue(command, "/Command/Uses/Use[" + MyXMLReader.SearchForValue_Int(command, new List<string>() { "/Command/Uses/Use/System" }, ((TabDocument)dockManager.ActiveDocument).version) + "]/Content");
}
if (MyXMLReader.SearchForValue(command, new List<string>() { "/Command/Notes/Note/System" }, ((TabDocument)dockManager.ActiveDocument).version))
{
txtBox_notes.Text = MyXMLReader.GetValue(command, "/Command/Notes/Note[" + MyXMLReader.SearchForValue_Int(command, new List<string>() { "/Command/Notes/Note/System" }, ((TabDocument)dockManager.ActiveDocument).version) + "]/Content");
}
Should I create a new string variable to hold
((TabDocument)dockManager.ActiveDocument).version?
Would this benefit with more speed and responsiveness? Will this be bad or good?
In short, yes.
The cost of repeatedly casting the
ActiveDocumenttoTabDocumentis probably negligible, but if you are looking to optimize, storing it into an intermediate variable is a step towards positive.But why you really should do it, is for code readability.