在我的代码中,我创建了一个带有以下内容的标签:
Label namelabel = new Label();
namelabel.Location = new Point(13, 13);
namelabel.Text = name;
this.Controls.Add(namelabel);
Run Code Online (Sandbox Code Playgroud)
名为name的字符串在此之前定义,长度约为50个字符.但是,只有前15个显示在我的表单上的标签中.我试过搞乱标签的MaximumSize,但无济于事.
我写了一个递归方法,从字符串中的字符中获取所有可能的字符组合.我也有一个方法来访问它并返回一个组合列表:
public static void uns(String word, StringBuilder s, List combos)
{
for(char c: word.toCharArray())
{
s.append(c);
if(word.length() != 1)
{
uns(removeChar(word, c),s,combos);
}
else
{
combos.add(s.toString());
}
s.deleteCharAt(s.toString().length()-1);
}
}
public static List getCombinations(String word)
{
List<String> combinations = new ArrayList<String>();
uns(word,new StringBuilder(),combinations);
return combinations;
}
public static String removeChar(String s, char c)
{
int index = s.indexOf(c);
return s.substring(0,index)+s.substring(index+1);
}
Run Code Online (Sandbox Code Playgroud)
在Java中测试时,它运行时没有任何缺陷.出于某种原因,当我在Android中使用它时,列表中填充了正确数量的元素,但每个元素都是相同的.例如,对于单词"here",它返回一个填充"eerh"的列表.
编写将遍历列表中每个2元素组合的控制结构的最佳方法是什么?
例:
{0,1,2}
Run Code Online (Sandbox Code Playgroud)
我希望有一个代码块运行三次,每次运行一次:
{0,1}
{1,2}
{0,2}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下内容
foreach (int i in input)
{
foreach (int j in input.Where(o => o != i))
{
//Execute code
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当列表具有两个相同的元素时,这将不起作用.同
{0,2,0}
Run Code Online (Sandbox Code Playgroud)
我仍然想比较元素0和0.价值无关紧要.
在C Sharp中,如何设置if语句来检查其中一个条件是否为真?它必须只是其中一个条件,如果为0或者两个或更多,则if应为false.
在WPF中:
<Button Width="24" Height="24" >
<Image Source="pack://application:,,,/res/x.png" VerticalAlignment="Center"/>
</Button>
Run Code Online (Sandbox Code Playgroud)
我怎样才能在C#中模仿这个?我在Button类中找不到添加子项的任何方法.
我有这样的事情:
int f = 120;
for(int ff = 1; ff <= f; ff++){
while (f % ff != 0){
}
Run Code Online (Sandbox Code Playgroud)
我的循环找到因素有什么问题吗?我对for和while语句的工作方式感到困惑,所以很可能他们完全错了.
在此之后,我将如何为所述因素分配变量?
我想获取数组目录中的所有文件(包括子文件夹中的文件)
string[] filePaths = Directory.GetFiles(@"c:\",SearchOption.AllDirectories);
Run Code Online (Sandbox Code Playgroud)
这个问题是:如果抛出异常,整个命令就会停止.有没有更好的方法来做到这一点,如果一个文件夹无法访问它只会跳过它?
我在台式机和笔记本电脑上开发,我经常在它们之间切换.将项目文件夹保留在我的Dropbox中并始终从那里访问/编辑可能会出现任何问题吗?我在两者上运行VS2010,但是W7在一个上,而W8在另一个上.
有没有办法在项目添加到ObservableCollection时触发事件,但是当一个项目被删除时没有?
我相信没有实际的事件,但也许是一种过滤CollectionChanged事件的方法?