System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list


        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder(); 
            string test = "124454664{0}89jnhb";
            string formattedMessage = string.Format(test, args);
   
        }

主要原因是字符串中有{}, 被string.Format调用时报错。

Replace即可。

            StringBuilder sb = new StringBuilder(); 
            string test = "124454664{0}89jnhb";
            test = test.Replace("{", "[").Replace("}", "]"); 
            string formattedMessage = string.Format(test, args);
   

或者 将 { 替换为 {{


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM