详情:

cs0116 C# a namespace cannot directly contain members such as fields or methods

报错代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace MethodTesting
{class Program{static void Main(string[] args){Console.WriteLine("Input a directory name:");string newDirectoryName = Console.ReadLine();Console.WriteLine("Input a file name with suffix:");string newFileName = Console.ReadLine();Console.WriteLine("Input a path:");string newPath = Console.ReadLine();//CreateDirectoryOrFile(newDirectoryName, newFileName, newPath);Console.WriteLine(newFileName);}}public static void CreateDirectoryOrFile(string newDirectoryName, string newFileName, string newPath){if (!newPath.Contains("\t\t")){newPath = @"C:\Users\Confidence\Desktop\";if (!Directory.Exists(newPath + newDirectoryName)){Directory.CreateDirectory(newPath + newDirectoryName);if (!File.Exists(newPath + newDirectoryName + "\\" + newFileName)){File.Create(newPath + newDirectoryName + "\\" + newFileName).Close();}}}}
}


正确代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace MethodTesting
{class Program{static void Main(string[] args){Console.WriteLine("Input a directory name:");string newDirectoryName = Console.ReadLine();Console.WriteLine("Input a file name with suffix:");string newFileName = Console.ReadLine();Console.WriteLine("Input a path:");string newPath = Console.ReadLine();CreateDirectoryOrFile(newDirectoryName, newFileName, newPath);Console.WriteLine(newFileName);}public static void CreateDirectoryOrFile(string newDirectoryName, string newFileName, string newPath){if (!newPath.Contains("\t\t")){newPath = @"C:\Users\Confidence\Desktop\";if (!Directory.Exists(newPath + newDirectoryName)){Directory.CreateDirectory(newPath + newDirectoryName);if (!File.Exists(newPath + newDirectoryName + "\\" + newFileName)){File.Create(newPath + newDirectoryName + "\\" + newFileName).Close();}}}}}
}

也就是说,在同一个命名空间下,新写的方法要在class之下,或者在struct下面。

点击链接以查看详情

C#中的cs0116Error相关推荐

  1. GNU Make 使用手册(于凤昌中译版)

    GNU Make 使用手册(中译版) 翻译:于凤昌 GNU make Version 3.79 April 2000 Richard M. Stallman and Roland McGrath 1 ...

  2. 面试:第十二章:所有总结

    Java基础 java基本类型哪些,所占字节 byte :1个字节 short :2个字节 char :2个字节 int :4个字节 long :8个字节 float :4个字节 double :8个 ...

  3. linux内核分析(转自某位大哥网上的笔记)

    启动 当PC启动时,Intel系列的CPU首先进入的是实模式,并开始执行位于地址0xFFFF0处的代码,也就是ROM-BIOS起始位置的代码.BIOS先进行一系列的系统自检,然后初始化位于地址0的中断 ...

  4. golang通过RSA算法生成token,go从配置文件中注入密钥文件,go从文件中读取密钥文件,go RSA算法下token生成与解析;go java token共用

    RSA算法 token生成与解析 本文演示两种方式,一种是把密钥文件放在配置文件中,一种是把密钥文件本身放入项目或者容器中. 下面两种的区别在于私钥公钥的初始化, init方法,需要哪种取哪种. 通过 ...

  5. 总结一下在使用某里云服务器的过程中出现过的一些问题

    此文总结在使用阿里云的过程中出现过的问题   想起来就记录一下 本人为言行负责! 海内选择腾讯华为,共勉! k8s不同命名空间的配置文件串掉了 k8s集群服务器购买上后,无法使用外网.连续购买了4台然 ...

  6. Kubernetes 中 设置pod不部署在同一台节点上

    在k8s中,节点的调度主要由亲和性和污点来进行控制的.   而在亲和性部分由分为了节点亲和性和节点反亲和性.   节点亲和性是指在pod部署时,尽量(软策略)或者必须满足(硬策略)部署在某些节点上. ...

  7. 在Dockerfile中设置G1垃圾回收器参数

    在Dockerfile中设置G1垃圾回收器参数 ENV JAVA_OPTS="\ -server \ -XX:SurvivorRatio=8 \ -XX:+DisableExplicitGC ...

  8. 在kotlin companion object中读取Bean,注入Bean对象

    在kotlin companion object中读取Bean,注入Bean对象 在使用kotlin时,或多或少地会使用到一些公共组件,如 http. mongo. redis相关的组件.   使用组 ...

  9. 在k8s中使用gradle构建java web项目镜像Dockerfile

    在k8s中使用gradle构建java web项目镜像Dockerfile FROM gradle:6-jdk8 AS build COPY --chown=gradle:gradle . /home ...

最新文章

  1. 静态反调试技术(3)
  2. 【转载】java中泛型使用详解
  3. Kafka集群环境搭建
  4. 如何打造组织级敏捷,你想知道的都在这里!
  5. ajax 返回flase,Django request.is_ajax返回false
  6. 室内主题元素分析图_2020届室内设计专业优秀毕业设计作品展(五)
  7. Yaffs2根文件系统制作
  8. 布尔运算,二进制和门电路
  9. sql2000执行sql2005导出的数据脚本时出现“提示含有超过64K限度的行”(转)
  10. STM32CubeMX使用(四)之DMA方式使用ADC
  11. BZOJ2157旅游——树链剖分+线段树
  12. 基地保留节目--塔防游戏
  13. 如何查看python标准库_python标准库
  14. 微型计算机中的西文字符编码,在微型计算机中,应用最普遍的西文字符编码是什...
  15. 项目管理(PMP)整体介绍
  16. 简谈浅层拷贝和深层拷贝
  17. linux 加速度传感器数据获取,对加速度传感器的数据进行方向和坐标的转换
  18. Android自动化测试技术——Espresso的使用
  19. 台式计算机是移动设备吗,超台式电脑!手机成中国第一大上网终端
  20. 华为服务器休眠远程怎么唤醒,华为路由WS5200怎么设置远程唤醒功能

热门文章

  1. 实践练习二:手动部署 OceanBase 集群
  2. 单片机定时器实现的数字时钟
  3. MyApps平台为政企数据保驾护航,筑牢办公安全防线
  4. 杰理之IIC sclk时钟【篇】
  5. 流行的任天堂电子游戏模拟器 Cemu 计划开源并支持 Linux
  6. 软件中的banner是什么意思??
  7. 解读 | 数据分析领域七大热门职业
  8. 2022年12月蓝桥STEMA评测C++中级组编程题
  9. 通过 Land of Lisp 中的超简短字符游戏例程学习 loop 和 format
  10. [翻译]在Windows版或MacOS版的Microsoft Edge上安装一个谷歌浏览器拓展