C#C
C#3y ago
morry329#

✅ why are they considered int instead of string?

So I was working on this puzzle https://leetcode.com/problems/backspace-string-compare/submissions/ I would like some advice on the compiler error/tipo (not the semantic/logical error to resolve this puzzle). My code is as follows, I am getting error CS1503: Argument 1: cannot convert from 'string' to 'int' (in Solution.cs) for two string initialisations inside the foreach-loop at the bottom. I had tried ToString()/Convert.ToString(), but to no avail. Could anyone kindly point me in the right direction?

public class Solution { public bool BackspaceCompare(string s, string t) { var dic1 = new Dictionary<string, string>(){ {" ", "#"}, {" ", "##"}, {" ", "###"} }; var dic2 = new Dictionary<string, string>(){ {" ", "#"}, {" ", "##"}, {" ", "###"} }; for(int i = 0; i < s.Length; i++){ string sStr = s[i].ToString(); string tStr = t[i].ToString(); if(!dic1.ContainsKey(sStr)){ dic1.Add(sStr, " "); } if(!dic2.ContainsKey(tStr)){ dic2.Add(tStr, " "); } } foreach(var k in dic1.Keys){ string sForEach = s[k].Convert.ToString(); //ERROR HERE string tForEach = t[k].Convert.ToString(); //ALSO HERE if(dic2.ContainsKey(k) && sForEach == tForEach){ return true; } } return false; } }
LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
Was this page helpful?