本文介绍了如何增加表名到表的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 静态字符串foldername; // foldername = table根据名称更改。 foreach(tablecontrol中的字符串tbl) { if(table1) { foldername = table1.foldername; // table1:一个表名:A } else if(table1) { foldername = table2.foldername; // table1:B so table name:B } else { foldername = table3.foldername; // table1:B所以表名:C } //写另一个区号 Directory.CreateDirectory(FilePath); - >我希望table3可以逐步调用。例如1个foldername1的名称,2个foldername1的名称等等。 我尝试了什么: foreach(tablecontrol中的字符串tbl) { if(table1) { foldername = table1.foldername } else if(table1) { foldername = table2.foldername } else { newcount ++; foldername = table3.foldername + newcount - > foldername1,foldername2,foldername3 } 此代码未运行。 newcount ++; foldername = table3.foldername + newcount //我想要C1,C2,C3但不能运行。 如何增加表名的表数? 解决方案 有点难以弄清楚你要做什么,但是如果要创建一个与表名匹配的目录,并附加一个数字,试试这样的话 int cnt = 0; foreach(tablecontrol中的字符串tbl) { string FilePath = string.Format({0} {1},tbl.TableName,++ cnt); Directory.CreateDirectory(FilePath); } static string foldername;//foldername = table changes according to name.foreach (string tbl in tablecontrol){ if(table1){ foldername= table1.foldername; //table1:A so table name: A} else if(table1){ foldername= table2.foldername; //table1:B so table name: B} else{ foldername= table3.foldername; //table1:B so table name: C}//write another area codeDirectory.CreateDirectory(FilePath); --> I want to table3 is be called incrementally. For example name for 1 foldername1 ,name for 2 foldername1....etc.What I have tried:foreach (string tbl in tablecontrol){ if(table1){ foldername= table1.foldername} else if(table1){ foldername= table2.foldername} else{ newcount++; foldername= table3.foldername +newcount --> foldername1,foldername2,foldername3}This code is not run.And the newcount++; foldername= table3.foldername +newcount // I want to C1,C2,C3 but not run.How do I increase the number of tables to the table name? 解决方案 Kinda hard to figure out what you are trying to do but if it is to create a directory that matches the table name with a number appended try some like thisint cnt =0;foreach (string tbl in tablecontrol){string FilePath = string.Format("{0}{1}", tbl.TableName, ++cnt); Directory.CreateDirectory(FilePath); } 这篇关于如何增加表名到表的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-12 04:46