How to resolve this error? : "Use of unassigned out parameter 'iCount'"

Wednesday, July 9, 2014

I have created a function with referenced parameter(with out keyword) and it can be called recursively. I want to get total number of file count from given folder path including sub-directories. So, I have created code like this.


My code is here.



private void getFileCount(string _path, out int iCount)
{
//in this line aplication gives error :Use of unassigned out parameter 'iCount'
iCount += Directory.GetFiles(_path).Length;

//Getting file count also from sub directories
foreach (string _dirPath in Directory.GetDirectories(_path))
getFileCount(_dirPath, out iCount);
}


The above function will be called like this.



public int getTotalFileCount()
{
int iCount = 0;
foreach (string _dirPath in Directory.GetDirectories(_path))
getFileCount(_dirPath, out iCount);
return iCount;
}


ADDITIONAL INFO: I am using .NET Framework 2.0 So, I cannot use LINQ







http://ift.tt/1kCW3cv