Witam,
Mam element typu string, czyli tablice ASCII. Chciałbym policzyć sumę wartości kodów tych elementów. Wiem że mogę sobie rozbić, później Convert.ToInt16(), ale czy są w c# jakieś mechanizmy, abym nauczył tego robić metodę Sum() ??
Witam,
Mam element typu string, czyli tablice ASCII. Chciałbym policzyć sumę wartości kodów tych elementów. Wiem że mogę sobie rozbić, później Convert.ToInt16(), ale czy są w c# jakieś mechanizmy, abym nauczył tego robić metodę Sum() ??
Mam element typu string, czyli tablice ASCII
UTF-16 a nie ASCII
ale czy są w c# jakieś mechanizmy, abym nauczył tego robić metodę Sum()
Na upartego...
using System;
using System.Collections.Generic;
using System.Linq;
static class test
{
public static IEnumerable<int> ToEnumerable(this string s)
{
foreach (char c in s) yield return c;
}
static void Main()
{
string s = "Ala ma kota";
Console.WriteLine(s.ToEnumerable().Sum());
}
}