用C#解释这个python表达式

Bay*_*len 1 c# python ironpython

这个python表达式的C#等价物是什么?

file_no = int (last_file.Name.Replace(last_file.Extension,"")[-3:]);
Run Code Online (Sandbox Code Playgroud)

我明白什么[-3:],但不是(int)演员.

jas*_*son 5

它用空字符串替换文件名的扩展名,将最后三个字符作为字符串,并尝试转换为int.

所以,如果last_filejamesbond007.secretagentlast_file.Extension.secretagentfile_no变成7因为.secretagent被替换为空字符串,而最后三个字符007被解析成7.

int file_no = 
    Int32.Parse(
        last_file.Name.Replace(
            last_file.Extension, String.Empty
        )
        .Right(3)
    );
Run Code Online (Sandbox Code Playgroud)