C
C#15mo ago
supriseX

❔ error CS1525: Unexpected symbol `String'

using System; public String DuplicateCount(string input) {
foreach (char a in input) { int i = a.Count; if (i > 1){ Console.WriteLine($"{a}:{i}");} }
} DuplicateCount("indivisibilities"); why doesn't this work?
13 Replies
leowest
leowest15mo ago
a.Count is invalid
supriseX
supriseX15mo ago
yes, but that's not the main problem here somehow String on line 3 isn't recognised
leowest
leowest15mo ago
what is line 3
supriseX
supriseX15mo ago
public String DuplicateCount(string input)
leowest
leowest15mo ago
well the other error is that your method does not have a return
supriseX
supriseX15mo ago
good point, im new to this so i forgot
leowest
leowest15mo ago
if you were using visual studio, it would have pointed those out for u what IDE are you using
supriseX
supriseX15mo ago
online, vs code is being weird, doesn't wanna run.
leowest
leowest15mo ago
ah well I suggest u use visual studio community instead its really helpful while learning so what are you trying to do here
foreach (char a in input)
{
int i = a.Count;
if (i > 1){
Console.WriteLine($"{a}:{i}");}
}
foreach (char a in input)
{
int i = a.Count;
if (i > 1){
Console.WriteLine($"{a}:{i}");}
}
are u trying to skip the first letter?
MODiX
MODiX15mo ago
Servator#3472
REPL Result: Success
var input = "indivisibilities";

var groups = input.GroupBy(c => c).Where(group => group.Count() > 1);

foreach (var group in groups)
{
Console.WriteLine($"{group.Key} {group.Count()}");
}
var input = "indivisibilities";

var groups = input.GroupBy(c => c).Where(group => group.Count() > 1);

foreach (var group in groups)
{
Console.WriteLine($"{group.Key} {group.Count()}");
}
Console Output
i 7
s 2
i 7
s 2
Compile: 810.352ms | Execution: 103.783ms | React with ❌ to remove this embed.
leowest
leowest15mo ago
ah yeah silly me should have read the method name so yeah what you want to do is, you might want to have a Dictionary to hold the char and count as you iterate in your loop and add to the dictionary and then loop thru the dictionary where your Value is bigger than one a is a char so you can't use Count like that which is why its invalid
supriseX
supriseX15mo ago
oh this is what i am trying to do tho thanks
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Newtonsoft json own read write methodHi there I want to serialized my struct to a json file and add support so specific types / field use❔ Calculating reading duration percentages for different time periodsI'm working on a project where I need to calculate the reading duration percentages for different ti❔ C# Rewrite ODT Links and download associated filesHello, I have a problem for several weeks on my c# code, my application is used to read an ODT file ❔ How to verify data according to DDD, SOLID and Clean Architecture?I own in two places one IF, it is: ```cs if(credential.Status != Credential.StatusType.Verified) ```✅ ✅ I can't display message in my dropdown if no data availablehttps://stackoverflow.com/questions/76199462/i-cant-display-message-in-my-dropdown-if-no-data-availa❔ Draggable markers on Gmap.NETI am using Gmap.NET and I'm trying to make the markers become draggable on the GUI. Any idea how to ❔ Using Allure for my tests but loading the report doesn’t usually workUsually when i try to open my report using “allure open “allure-report”” The server starts but acce❔ Using inheritance in my projectI'm building a book shelf project and I need help with modifying my ctor so I could assign each inpu✅ How to Save HighScore in each difficulty separately?I don't know how to save players HighScore for each difficulty separately, so that it will not be th❔ how to turn off computer 1 from computer 2 with his ip and connected to the same networkhello how do i shutdown a computer remotly with ip? shutdown /m \\{IP}/s /t 3 thats what im doing in