TypeError: Explicit type conversion not allowed from "uint256" to "address". Need some help

Getting the following error: TypeError: Explicit type conversion not allowed from "uint256" to "address" with the code below specifically at: holders[index] = address(i);

uint256 index = 0;
        for (uint256 i = 0; i < _reflectionFeeTotal; i++) {
            if (_balances[holders[i]] > 0) {
                holders[index] = address(i);
                index++;
            }
        }
        
        return holders;
    }
}

Any advice would help. I'm learning.

The size of type address is 160 bits.

The size of i, which is of type uint256, is 256 bits.

So you need to truncate it to 160 bits before casting it from uint256 to address:

address(uint160(i))

You can also just use a uint160 i counter in that loop to begin with...


Regardless of the above, you might also wanna ask yourself why on earth you are doing this:

holders[index] = address(i)

If anything, it sounds like you should be doing this:

holders[index] = holders[i]

Thanks for the help. I did it that way because I am not literate enough in code. Thanks again!