0

How can I use two of the following Get Directories? I need to add them into one int, but when I use the following code I just get the same numbers.

var directoryInfo = new System.IO.DirectoryInfo(@"c:\test\");
int directoryCount = directoryInfo.GetDirectories().Length;

var directoryInfo2 = new System.IO.DirectoryInfo(@"c:\test2\");
int directoryCount2 = directoryInfo.GetDirectories().Length;

int directoryCountMain = directoryCount + directoryCount2;
4

1 回答 1

1

2directoryCount2初始化声明中丢失了。

您使用directoryInfo.GetDirectories().Length了两次,而不是directoryInfo2在设置时使用 object directoryCount2

var directoryInfo2 = new System.IO.DirectoryInfo(@"c:\test2\");
int directoryCount2 = directoryInfo2.GetDirectories().Length;
于 2013-09-07T16:56:05.560 回答