English 中文(简体)
简单的C# WPF形成一种表面似非主观错误的信息
原标题:Simple C# WPF form generating a slew of seemingly nonsensical error messages

下面的法典载有错误信息的“全方位”信息,我可以为我的生活指明原因。 我最近不得不“从VS2010到VS2008年降级”,自那以来没有任何痛苦。 头几个错误信息在出现的地方被作为评论显示。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace UniClient_NextGen
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void buttonPopMenuItemsLU_Click(object sender, RoutedEventArgs e) 
        { // err msg #1 = "} expected"
            public static int TOPLEVEL_ID = 0;
            public static int PARENT_ID = 1;
            public static int SELF_ID = 2;
            public static int MENU_CAPTION = 3;
            public static int MENU_NAME = 4;

            string fileName = @"C:\_UniClientNextGenMenuItemsWithIDs.txt";
            using (StreamReader reader = File.OpenText(fileName)) // err msg #2 = "Invalid token  using  in class, struct, or interface member declaration" + err msg #3 = "; expected" (at end of this line)
            {
                string _line = null;
                string[] strElements;
                do
                {
                    _line = reader.ReadLine();
                    strElements = _line.Split(",");
                    // strElements should now have five elements
                    int iTopLevelID = Convert.ToInt32(strElements[TOPLEVEL_ID]);
                    int iParentID = Convert.ToInt32(strElements[PARENT_ID]);
                    int iOwnID = Convert.ToInt32(strElements[SELF_ID]);
                    string sMenuCaption = strElements[MENU_CAPTION];
                    string sMenuName = strElements[MENU_NAME];
                    //performSQL("INSERT INTO MENU_ITEMS_LOOKUP (TopLevelMenuID, ParentMenuID, MenuItemName, MenuItemCaption) VALUES (iTopLevelID, iParentID, iOwnID, sMenuCaption, sMenuName)");
                } while (_line != null);
            }
        } // err msg #4 = "Type or namespace definition, or end-of-file expected" 

        private void buttonPopSorterTypesLU_Click(object sender, RoutedEventArgs e)
        {
            //
        }

        private void buttonPopTabsheetsLU_Click(object sender, RoutedEventArgs e)
        {
            //
        }

        private void buttonPopMenuItem_SorterTypeM2M_Click(object sender, RoutedEventArgs e)
        {
            //
        }

        private void buttonPopSorterType_TabsheetM2M_Click(object sender, RoutedEventArgs e)
        {
            //
        }
    }
}
最佳回答

这里是经过更正的法典(我已把静态成员声明移至正确的位置,并更正了——线。

//...
public static int TOPLEVEL_ID = 0;
public static int PARENT_ID = 1;
public static int SELF_ID = 2;
public static int MENU_CAPTION = 3;
public static int MENU_NAME = 4;

void buttonPopMenuItemsLU_Click(object sender, RoutedEventArgs e) {
    string fileName = @"C:\_UniClientNextGenMenuItemsWithIDs.txt";
    using(StreamReader reader = File.OpenText(fileName)) {
        string _line = null;
        string[] strElements;
        do {
            _line = reader.ReadLine();
            strElements = _line.Split( , );
            int iTopLevelID = Convert.ToInt32(strElements[TOPLEVEL_ID]);
            int iParentID = Convert.ToInt32(strElements[PARENT_ID]);
            int iOwnID = Convert.ToInt32(strElements[SELF_ID]);
            string sMenuCaption = strElements[MENU_CAPTION];
            string sMenuName = strElements[MENU_NAME];
        } while(_line != null);
    }
}
//...
问题回答

为什么在某种方法内有<条码>公开静态的声明?

我认为,你对XAML定义或XAML名称空间的重新定义与你的类别不符。 您最近是否改名为某类或名称空间?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签