小编Oma*_*mar的帖子

变量未声明或从未分配警告

我有这样的代码:

这是基类:

public class BaseClass : UserControl
{
     protected ListView list;
     protected TreeView tree;

     public BaseClass()
     {
         //...
     }
     //...
}
Run Code Online (Sandbox Code Playgroud)

儿童班

public partial class MyClass : BaseClass
{
     public MyClass()
     {
         InitializeComponent();
         this.BackColor = VisualStyleInformation.TextControlBorder;
         this.Padding = new Padding(1);
     }
     //...
}

partial class MyClass
{
    //...

    private void InitializeComponent()
    {
         this.tree = new System.Windows.Forms.TreeView();
         this.list = new System.Windows.Forms.ListView();
         //...
         this.tree.Location = new System.Drawing.Point(0, 23);
         this.tree.Name = "blablabla";
    }
}
Run Code Online (Sandbox Code Playgroud)

并警告:

Warning 1 The variable 'tree' is either undeclared …
Run Code Online (Sandbox Code Playgroud)

.net c# winforms

5
推荐指数
1
解决办法
1万
查看次数

将字符串(System.String)转换为类型

我正在尝试创建一个通用的XML到对象转换器.换句话说,以下是我的XML

<setting>
   <name>testing</name> 
   <type>System.String</type>
   <defaultObj>TTTT</defaultObj>
</setting>
Run Code Online (Sandbox Code Playgroud)

type字段保存其加载的对象的类型.这只是我所选择的对象结构.无论如何,我遇到了转换问题

System.String
Run Code Online (Sandbox Code Playgroud)

到一个实际的类型变量.所以,例如,为了转换我有以下代码:

foreach (XNode node in document.Element(root).Nodes())
{
   T variable = new T(); //where T : new()

   foreach (FieldInfo field in fields)
   {
      field.SetValue(variable, Convert.ChangeType(((XElement)node).Element(field.Name).Value, field.FieldType));
   }

   retainedList.Add(variable);
}
Run Code Online (Sandbox Code Playgroud)

以通用方式获取对象.该算法完美运行,直到遇到Type字段.我得到一个:

Invalid cast from 'System.String' to 'System.Type'.
Run Code Online (Sandbox Code Playgroud)

运行时错误.据我所知,直接将类型标识符(字符串)直接转换为类型存在问题.我不知道如何解决这个问题,至少在保持通用和清洁方面.有任何想法吗?如果问题有点模糊,我很抱歉,如果你不太明白我会尝试进一步澄清.任何帮助是极大的赞赏!

c# xml linq

5
推荐指数
2
解决办法
1万
查看次数

Nhunspell C#将词添加到词典中

我已经设法使用NHunspell将拼写检查合并到我的C#项目中.我想要做的是实际上在字典文件中添加一个单词.在NHunspell内部有一种方法可以做到这一点,我相信如下:

// Add the word to the dictionary and carry on
using (Hunspell hunspell = new Hunspell(@"Dictionaries/en_GB.aff", @"Dictionaries/en_GB.dic"))
{
    hunspell.Add("wordToAdd");                
}
Run Code Online (Sandbox Code Playgroud)

当我使用它时,它实际上似乎没有做任何事情.有人能够建议我做错了什么吗?

谢谢

c# spell-checking hunspell

4
推荐指数
1
解决办法
2682
查看次数

4
推荐指数
2
解决办法
2万
查看次数

使用Html Agility Pack解析表

我有一张桌子

<table>
        <tr class="odd">
        <td class="ind gray">1</td>
        <td><b>acceding</b></td>
        <td class="transcr">[?ks?i?d??]</td>
        <td class="tran">?????????????</td>
      </tr>
<!-- .... -->
        <tr class="odd">
        <td class="ind gray">999</td>
        <td><b>related</b></td>
        <td class="transcr">[r?l?e??t?d]</td>
        <td class="tran">???????????</td>
      </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

我想要在一行中解析三个"td".我的代码

Dictionary<string, Word> words = new Dictionary<string, Word>();
string text = webBrowser1.DocumentText;
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(text);
for (int i = 0; i < doc.DocumentNode.SelectNodes("//tr").Count; i++)
{
     HtmlNode node = doc.DocumentNode.SelectNodes("//tr")[i];
     Word word = null;
     if (TryParseWord(node, out word))
     {
          try
          {
               if (!words.ContainsKey(word.eng))
               {
                    words.Add(word.eng, word);
               }
          }
          catch
          { …
Run Code Online (Sandbox Code Playgroud)

c# html-agility-pack

4
推荐指数
1
解决办法
8550
查看次数

从c#中的文件夹中复制所有类型格式文件

我试图将所有格式文件(.txt,.pdf,.doc ...)文件从源文件夹复制到目标.

我只为文本文件编写代码.

我该怎么做才能复制所有格式文件?

我的代码:

string fileName = "test.txt";
string sourcePath = @"E:\test222";
string targetPath =  @"E:\TestFolder"; 

string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
Run Code Online (Sandbox Code Playgroud)

复制文件的代码:

System.IO.File.Copy(sourceFile, destFile, true);
Run Code Online (Sandbox Code Playgroud)

c#

4
推荐指数
2
解决办法
7321
查看次数

方法'METHOD'没有重载需要0个参数

我有3种方法.

1方法保持值为3000 1的方法保持值为0.13

我已经创建了另一种方法,我希望将这两个数字相乘.

public override int FishPerTank()
{                
    return 3000;                
}

public override double WeightOut(double weightOut, double weightIn)
{
    return 0.13;
}

public override int HowMuchTheFishWeighOutKG()
{
    return (FishPerTank() * WeightOut());
}
Run Code Online (Sandbox Code Playgroud)

我在这里收到WeightOut上的语法错误:

public override int HowMuchTheFishWeighOutKG()
{
    return (FishPerTank() * WeightOut());
}
Run Code Online (Sandbox Code Playgroud)

c# overloading winforms

4
推荐指数
3
解决办法
8622
查看次数

C#中的OpenFileDialog

如何从打开文件对话框中获取结果(表示文件名及其位置)?

我的代码:

private void selectFileButton_Click( object sender, EventArgs e ) {
    var selectedFile = selectFileDialog.ShowDialog();
    //label name = fileName
    fileName.Text = //the result from selectedFileDialog
}
Run Code Online (Sandbox Code Playgroud)

c# label dialog winforms

4
推荐指数
2
解决办法
2万
查看次数

如何画出一个圆圈?

我正在根据我的C代码的规范创建位图/ bmp文件,我想在我的位图上绘制简单的基元.以下代码显示了如何在位图上绘制矩形:

if(curline->type == 1) // draw a rectangle
{
    int xstart = curline->x;
    int ystart = curline->y;
    int width = curline->width + xstart;
    int height = curline->height + ystart;

    int x = 0;
    int y = 0;

    for(y = ystart; y < height; y++)
    {
      for(x = xstart; x < width; x++)
      {
        arr[x][y].blue = curline->blue;
        arr[x][y].green = curline->green;
        arr[x][y].red = curline->red;
      }
    }

    printf("rect drawn.\n");
}

...
save_bitmap();
Run Code Online (Sandbox Code Playgroud)

示例输出: 在此输入图像描述

所以基本上我为给定的x和y字段中的所有像素设置红色,绿色和蓝色值.

现在我想知道它的中点和半径来填充一个圆圈.但是我如何知道这个圆圈内的像素和哪些像素不是?任何帮助将不胜感激,感谢阅读.

c c++

4
推荐指数
1
解决办法
1万
查看次数

如何通过createBottomTabNavigator为每个选项卡使用不同的图标?

我正在React Native Navigation v2为我的项目使用。我正在尝试使用设置两个不同的IonIcons createBottomTabNavigator

他们的网站提供了这样的示例:

navigationOptions: ({ navigation }) => ({
  tabBarIcon: ({ focused, tintColor }) => {
    const { routeName } = navigation.state;
    let iconName;
    if (routeName === 'Home') {
      iconName = `ios-information-circle${focused ? '' : '-outline'}`;
    } else if (routeName === 'Settings') {
      iconName = `ios-options${focused ? '' : '-outline'}`;
    }

    // You can return any component that you like here! We usually use an
    // icon component from react-native-vector-icons
    return <Ionicons …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native react-navigation

4
推荐指数
1
解决办法
5955
查看次数