I am reading a text file that and storing it to an array. During the process of creating the array I call for the character key and the frequency count. I need to be able to get the Ascii value of each character that is read from the file.
I have tried byte[] asciiBytes = Encoding.ASCII.GetBytes(count);
but I can't use count as it can't be converted from Characterfrequency()
class CharacterFrequency
{
public int Frequency { get; set; }
public char Char { get; set; }
public byte Ascii { get; set; }
public override string ToString()
{
return $"Character: {Char} Frequency: {Frequency}";
}
Below is the class that loops through the file.
class Program : CharacterFrequency
{
static void Main(string[] args)
{
var count = File.ReadAllText("wap.txt")
.ToCharArray()
.GroupBy(x => x)
.Select(x => new CharacterFrequency() { Char = x.Key, Frequency = x.Count()
})
.ToArray();
foreach (var item in count)
Console.WriteLine($"{item.Char} {item.Frequency}");
Console.ReadLine();
In the foreach it should loop through and print out the the data on each line like: Character: A(65) Frequency: 250