字符串到char数组c#导致错误

字符串到char数组c#导致错误,第1张

概述基本上我在C#中制作一个刽子手游戏,但问题是每当我尝试用word.ToCharArray()将我的字符串单词转换为char []时.这是行不通的. 有人能弄清楚这段代码有什么问题吗? List<string> words = new List<string>();List<string> guessedLetters = new List<string>();string word = "sw 基本上我在C#中制作一个刽子手游戏,但问题是每当我尝试用word.tochararray()将我的字符串单词转换为char []时.这是行不通的.

有人能弄清楚这段代码有什么问题吗?

List<string> words = new List<string>();List<string> guessedLetters = new List<string>();string word = "sword";// Turning word into char arraychar[] letters = word.tochararray();

CS0236 A fIEld initializer cannot reference the non-static fIEld,method,or property ‘Form1.word’ final C:\Users*\Desktop\final\final\Form1.cs 20 Active

解决方法 到目前为止已知的是,你有一个名为Form1的类:

public class Form1 {      List<string> words = new List<string>();      List<string> guessedLetters = new List<string>();      string word = "sword";      //...      public static voID Main(string[]args){          char[] letters = word.tochararray();       }}

如果是这种情况那么,你做错了.您将需要Form1类的对象来使用变量word.

public static voID Main(string[]args){          Form1 F1 = new Form1();          char[] letters = F1.word.tochararray();       }
总结

以上是内存溢出为你收集整理的字符串到char数组c#导致错误全部内容,希望文章能够帮你解决字符串到char数组c#导致错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1233154.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存