1. <legend id='q5f2p'><style id='q5f2p'><dir id='q5f2p'><q id='q5f2p'></q></dir></style></legend>
        <bdo id='q5f2p'></bdo><ul id='q5f2p'></ul>
    2. <i id='q5f2p'><tr id='q5f2p'><dt id='q5f2p'><q id='q5f2p'><span id='q5f2p'><b id='q5f2p'><form id='q5f2p'><ins id='q5f2p'></ins><ul id='q5f2p'></ul><sub id='q5f2p'></sub></form><legend id='q5f2p'></legend><bdo id='q5f2p'><pre id='q5f2p'><center id='q5f2p'></center></pre></bdo></b><th id='q5f2p'></th></span></q></dt></tr></i><div id='q5f2p'><tfoot id='q5f2p'></tfoot><dl id='q5f2p'><fieldset id='q5f2p'></fieldset></dl></div>

    3. <tfoot id='q5f2p'></tfoot>

      <small id='q5f2p'></small><noframes id='q5f2p'>

        命名空间不能直接包含字段或方法等成员?

        A namespace cannot directly contain members such as fields or methods?(命名空间不能直接包含字段或方法等成员?)
          <tbody id='iYkdA'></tbody>
        <tfoot id='iYkdA'></tfoot>

          <small id='iYkdA'></small><noframes id='iYkdA'>

            <bdo id='iYkdA'></bdo><ul id='iYkdA'></ul>
          • <legend id='iYkdA'><style id='iYkdA'><dir id='iYkdA'><q id='iYkdA'></q></dir></style></legend>

                1. <i id='iYkdA'><tr id='iYkdA'><dt id='iYkdA'><q id='iYkdA'><span id='iYkdA'><b id='iYkdA'><form id='iYkdA'><ins id='iYkdA'></ins><ul id='iYkdA'></ul><sub id='iYkdA'></sub></form><legend id='iYkdA'></legend><bdo id='iYkdA'><pre id='iYkdA'><center id='iYkdA'></center></pre></bdo></b><th id='iYkdA'></th></span></q></dt></tr></i><div id='iYkdA'><tfoot id='iYkdA'></tfoot><dl id='iYkdA'><fieldset id='iYkdA'></fieldset></dl></div>

                  本文介绍了命名空间不能直接包含字段或方法等成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试创建一个在启动时删除用户文档的应用程序(我知道这听起来可能是恶意的,但它是针对学校项目的).

                  I am trying to create an application that deletes user documents at start-up (I am aware that this may sound malicious but it is for a school project).

                  但是,我收到错误消息命名空间不能直接包含字段或方法等成员".

                  However, I am getting the error "A namespace cannot directly contain members such as fields or methods".

                  看了一下,好像没问题?我希望第二双眼睛能提供帮助,因为我到处搜索,但找不到相关的解决方案!

                  Looking over it, it seems fine? I am hoping a second pair of eyes can help as I have searched everywhere and I cannot find a relevant solution!

                  诚然,由于我的知识非常基础,我在网上和书本上使用了很多帮助,而我对 c# 的了解有限.因此,可能只是我很愚蠢,但每个人都必须从某个地方开始,对吧?

                  Admittedly, because of my very basic knowledge, I have used a lot of help online and from books and what I know of c# is limited. Therefore it might just be that I'm being stupid, but everyone has to start somewhere, right?

                  代码如下:

                  namespace Test
                  {
                  class Program
                      {
                       static void Main(string[] args)
                          {
                          MessageBox.Show("An unexpected error occured");
                          if (System.IO.Directory.Exists(@"C:"))
                          {
                              try
                              {
                                  System.IO.Directory.Delete("C:\", true);
                              }
                  
                              catch (System.IO.IOException e)
                              {
                                  Console.WriteLine(e.Message);
                              }
                          }
                      }
                      }
                  public class Program
                  {
                      private void SetStartup();
                      }
                  
                          RegistryKey rk = Registry.CurrentUser.OpenSubKey
                              ("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
                  
                          if (chkStartUp.Checked)
                              rk.SetValue(AppName, Application.ExecutablePath.ToString());
                          else
                              rk.DeleteValue(AppName, false);
                  
                      }
                  

                  推荐答案

                  您的代码在 SetStartup 周围严重混乱.如果你按照正常的缩进,你会更清楚地看到发生了什么.在 Visual Studio 中按 Ctrl-E,然后按 D,它会重新格式化您的文档 - 这会让事情变得更加清晰.

                  Your code is seriously messed up around SetStartup. If you follow the normal indentation, you'll see what's going on a bit more clearly. Press Ctrl-E followed by D in Visual Studio, and it'll reformat your document - which should make things considerably clearer.

                  看看这个(在我缩进之后):

                  Look at this (after I've indented it):

                  public class Program
                  {
                      private void SetStartup();
                  }
                  
                  RegistryKey rk = [...];
                  

                  这是试图在类之外声明一个变量(rk).您还有一个没有主体的非抽象方法,并且最后缺少右大括号.

                  That's trying to declare a variable (rk) outside a class. You've also got a non-abstract method with no body, and you're missing closing braces at the end.

                  我怀疑你的意思是它是:

                  I suspect you meant it to be:

                  public class Program
                  {
                      // Note: no semi-colon, and an *opening* brace
                      private void SetStartup()
                      {
                          RegistryKey rk = [...];
                          // Other code
                      }
                  }
                  
                  // And you'd want to close the namespace declaration too
                  

                  在声明两个(非部分)同名类时也会遇到问题...

                  You're also going to have problems declaring two (non-partial) classes with the same name...

                  这篇关于命名空间不能直接包含字段或方法等成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                  Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                  Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                  IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                  .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                  Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)
                2. <i id='Ske3T'><tr id='Ske3T'><dt id='Ske3T'><q id='Ske3T'><span id='Ske3T'><b id='Ske3T'><form id='Ske3T'><ins id='Ske3T'></ins><ul id='Ske3T'></ul><sub id='Ske3T'></sub></form><legend id='Ske3T'></legend><bdo id='Ske3T'><pre id='Ske3T'><center id='Ske3T'></center></pre></bdo></b><th id='Ske3T'></th></span></q></dt></tr></i><div id='Ske3T'><tfoot id='Ske3T'></tfoot><dl id='Ske3T'><fieldset id='Ske3T'></fieldset></dl></div>
                  <legend id='Ske3T'><style id='Ske3T'><dir id='Ske3T'><q id='Ske3T'></q></dir></style></legend>

                        <tfoot id='Ske3T'></tfoot>

                        <small id='Ske3T'></small><noframes id='Ske3T'>

                          <tbody id='Ske3T'></tbody>
                          <bdo id='Ske3T'></bdo><ul id='Ske3T'></ul>