*紧急*为什么不让我使用Console.WriteLine()??????? [英] *URGENT* Why won't it let me use Console.WriteLine() ???????
问题描述
我的程序没有完成但有人可以告诉我为什么我不能在Main类中使用Console.WriteLine?
My program is not done but can someone please tell me why I can't use Console.WriteLine in the Main class?
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Text;
namespace Huffman_Codes
{
class Main
{
Console.WriteLine("blah blah");
}
class Node : IComparable
{
public char Character { get; set; }
public int Frequency { get; set; }
public Node Left { get; set; }
public Node Right { get; set; }
public Node (char character, int frequency, Node left, Node right)
{
}
public int CompareTo (Object obj)
{
}
}
class Huffman
{
private Node HT; // Huffman tree to create codes and decode text
private Dictionary<char, string> D; // Dictionary to encode text
private string S;
// Constructor
public Huffman (string strings)
{
S = strings;
}
// Return the frequency of each character in the given text (invoked by Huffman)
private int[] AnalyzeText (string S)
{
int[] F = new int[S.Length];
var characterCount = new Dictionary<char, int>();
foreach (var ch in S)
{
if (characterCount.ContainsKey(ch))
characterCount[ch]++;
else
characterCount[ch] = 1;
}
int index = 0;
foreach(var val in characterCount)
{
F[index] = (val.Value);
index++;
}
return F;
/* foreach (var pair in characterCount)
{
Console.WriteLine("{0} - {1}", pair.Key, pair.Value);
}
Console.ReadLine();
*/
}
// Build a Huffman tree based on the character frequencies greater than 0 (invoked by Huffman)
private void Build ( int[] F)
{
PriorityQueue<Node> PQ;
}
// Create the code of 0s and 1s for each character by traversing the Huffman tree (invoked by Huffman)
private void CreateCodes ()
{
}
// Encode the given text and return a string of 0s and 1s
public string Encode (string S)
{
}
// Decode the given string of 0s and 1s and return the original text
public string Decode (string S)
{
}
}
}
推荐答案
您只能在方法中编写Console.WriteLine,但您已将其直接写入类中,而无需添加方法。
You can only write Console.WriteLine inside a method, but you have written it directly inside a class, without adding a method.
也就是说,你写了
class Main {Console.WriteLine(...); }
class Main { Console.WriteLine(...); }
但你需要:
class Something {public static void Main {Console.WriteLine(...); }}
class Something { public static void Main { Console.WriteLine(...); } }
请注意,您将类命名为"Main"。这是合法的,但它会引起混淆,因为我们通常使用"Main"。命名用作程序入口点的方法。
Note that you named your class "Main". This is legal, but it will cause confusion because we normally use "Main" to name the method that serves as entry point to the program.
这篇关于*紧急*为什么不让我使用Console.WriteLine()???????的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!