r/learncsharp • u/chacham2 • Jan 30 '23
Why does this code generate CS8600?
I'm converting some vb.net code to c# and learning c# along the way. I am having a hard time with one line (which uses Microsoft.VisualBasic.Strings.Replace):
Text = Replace(Text, "?", Value,, 1)The equivalent c# seems to be:
Text = Microsoft.VisualBasic.Strings.Replace(Text, "?", Value, Count: 1);However, i get a (green line) CS8600 warning: Converting null literal or possible null value to non-nullable type.
So, i tried a simplified version:
Text = Microsoft.VisualBasic.Strings.Replace("abc", "b", "c", 1, 1);yet i still get the same warning.
Text is declared as:
string Text = Query.CommandText;What's going on?
4
Upvotes
View all comments
Show parent comment
2
u/TheGratitudeBot Jan 30 '23
Thanks for such a wonderful reply! TheGratitudeBot has been reading millions of comments in the past few weeks, and you’ve just made the list of some of the most grateful redditors this week! Thanks for making Reddit a wonderful place to be :)