Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
int age;
string name;
Console.WriteLine ("Hello!");
Console.WriteLine ("What is your name?");
name = Console.ReadLine();
if (name = Max H); // **error is here**
{
Console.WriteLine ("Psst you're a nerd lmao");
}
else{
Console.WriteLine ("Hello, " + name );
}
Basically I want it so if there's a specific answer it'll give a different reply to the default answer.
main.cs(13,16): error CS0103: The name 'Max H' does not exist in the
current context =
The error I get.
TwoThree errors:
Comparing needs a double =, so ==
That "Max H" is a string constant, so must be in double quotes.
After the if, you don't want a ; as that ends the if. The next line will be executed always, except that the compiler will trip over that else (thanks RetiredNinja)
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
when I try to use TryParse I get error CS0029, pls see below:
static void Main(string[] args)
{
double m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12;
double notval = 0;
Console.WriteLine("Please insert the rainfall in January:");
m1 = double.TryParse(Console.ReadLine(), out notval) ;
I get the error "Cannot implicitly convert type 'bool' to 'double'" (CS0029).
TryParse returns of it was successful at parsing or not, and puts the result (if successful) in the out parameter (on you case notval).. so use:
if(double.TryParse(Console.ReadLine(), out notval))
{
// Do what you want with notval
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am trying to check to see if this object contains any letters besides Z and if it does it should return Null. The way I have it initialized gives me no errors but when testing it does not actually return null if a letter is present.
if(request.DoorTag.Contains(#"[a - yA - Y]"))
{
return null;
}
if(Regex.IsMatch(request.DoorTag, "[a-yA-Y]")
{
return null;
}
But "[^zZ]" would even be better, since it'll check that your DoorTag contains any other char than Z
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm new to programming and I have just installed Visual Studio 2017. I created this code (from the book I'm learning), but this does not compile. I have problem with string interpolation and I get error:
Unexpected character '$',
but I'm using C# 6.0 so this should not be a problem ?
static void Main(string[] args)
{
string comparison;
WriteLine("Enter the number:");
double var1 = ToDouble(ReadLine());
WriteLine("Enter another number :");
double var2 = ToDouble(ReadLine());
if (var1 < var2)
comparison = "less than";
else
{
if (var1 == var2)
comparison = "equal to";
else
comparison = "greater than";
}
WriteLine($ "The first number is {comparison} the second number");
ReadKey();
}
It is a very small problem :) Remove space after $:
WriteLine($"The first number is {comparison} the second number");
See proper structure under documentation:
$"<text> {<interpolated-expression> [,<field-width>] [:<format-string>] } <text> ..."
I've requested an edit that explains that there must be no spacing after the $ and now it states:
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
string input= "hello, how are you today"
i knw the encode is not in proper format thats why i am using a function to replace improper "today" to "today".
f1(input);
but at time of comparing
if (input.Contains("today") == true)
{
lbldisplay.Text = str1;
}
it returing false,i have debugged the program.it is working correctly till replace s1.Replace("a","a");(shown "hello, how are you today") but at return statement return s1; it is returning original value i.e "hello, how are you today".
public string f1(string s1)
{
s1 = s1.Replace("a", "a");
return s1;
}
please help.thank you.
Most likely what is happening is that you're not assigning the return value back to your variable when you call it. The parameter is not declared ref so this will have no effect:
f1(input);
You would need to use this:
input = f1(input);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Trying to use the .NET SubString function. I pass a value to a custom function and then an if statement evaluates if it should be capitalized or not. Then I use the following to change the first letter to upper case. However, it tells me that the "Index was outside the bounds of the array." What am I doing wrong?
char.ToUpper(X[0]) + X.Substring(1)
Wrap it in isNullOrEmpty()
if(!string.IsNullOrEmpty(X))
{
char.ToUpper(X[0]) + X.Substring(1)
}
This might help you out, as it has some sanity checks included
public string FirstLetterToUpper(string str)
{
if (string.IsNullOrEmpty(str))
return str;
return char.ToUpper(str[0]) + str.Substring(1);
}