Axxelsian
Axxelsian

Reputation: 807

Code efficiency in C#

I am working with a treeview that contains nodes from a directory, where the lowest node is a piece of text from a file. I would like to be able to get that node, and get it's filename, and ive done so in the following line of code, but is there a nicer way of doing this? I want it to be as efficient as possible, and i'm wondering if its better to just create an integer to store the index number, rather than calculating it in the index itself. I know if the integer variable is created i will have to do that calculation anyway...

(tVSNodes is a list of treenodes)

TL:DR - is there a more efficient(faster execution) way of doing this?

string filename = tVSNodes[0].FullPath.Split('\\')[(tVSNodes[0].FullPath.Split('\\').Count()-2)];

Upvotes: 1

Views: 200

Answers (1)

Austin Salonen
Austin Salonen

Reputation: 50225

It looks like you're just trying to get the text of the parent node.

if (tVSNodes[0].Parent == null)
     return;  // handle appropriately

string fileName = tVSNodes[0].Parent.Text;

Upvotes: 4

Related Questions