Why this compilation difference? [closed] - c#

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 7 years ago.
Improve this question
Don't know what to title it, but here's what I have.
As you can see I have following lines of code where 1st and 2nd lines are okay but third line is causing error.
Can someone explain why? I have a feeling that it might be because (s is PaymentSchdule) needs to be evaluated at runtime, is that the reason?

Your syntax is incorrect. To check if something is of a specified type:
s is PaymentSchedule
Not
s is PaymentSchedule()
Resulting in you changing you code to:
Console.WriteLine("PaymentSchedule: " + (s is PaymentSchedule).ToString() + "Code: " + s.GetHashCode());
I'd be tempted to write it like this for better readability, though:
Console.WriteLine("PaymentSchedule: {0} Code: {1}", s is PaymentSchedule, s.GetHashCode());

You have written PaymentSchedule(). It should be PaymentSchedule

Related

Equivalent strings that look exactly the same but arn't equal in Unity [closed]

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 1 year ago.
Improve this question
An public string ItemSubType which is assigned a string "primary" by another script is somehow not equal to the string "primary". I've checked for empty characters but there isn't any. I've been absolutly stumped by this but also interested in how this is happening.
Debug.Log("---primary---");
Debug.Log("---" + ItemSubType + "---");
if(ItemSubType != "primary")
{
Debug.Log("This is ridiculous!");
}
Here is logs:A picture of the log
Thank you all for the comments!
After browsing through some other questions, I found .Trim().
Mystically there seems to be an invisible character in the string that isn't a whitespace character, as would be evident by the lack of spaces when adding '---' to either side.
By doing this:
ItemSubType = ItemSubType.Trim();
It fixed the Issue. To give some context, I pulled the string data from a csv file. I checked the file for any extra spaces but there wasn't any. Not sure if this is related tho.

Syntax error "," expected but i can't find it (C# Unity) [closed]

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
private int skor 0;
it says "syntax error "," expected" and i cant figure out why i am very new at unity sorry if it has a very obvious answer.
You are missing assignment operator = in your skor declaration:
private int skor = 0;

The left-hand side of an assignment must be a variable property or indexer - property can't be set [closed]

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 3 years ago.
Improve this question
SML is a property of regelSML. I want to set regelSML to a value given by Reader.getString(i).
if(reader.GetName(i) = "SML") regelSML.SML = reader.GetString(i);
As clarification, like Guy wrote in the comments above, you are not doing a comparison in the condition.
A single = is for assignments.
You need the comparison-operator ==.

Issue with SubString function [closed]

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);
}

String = (Convert(String) - 1).ToString [closed]

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
Well, I need to subtract the number from a string, and in the end she should continue being a string ...
I try:
PStruct.character[Index, PStruct.player[Index].SelectedChar].Y =
(Convert.ToInt32(PStruct.character[Index, PStruct.player[Index].SelectedChar].Y) - 1)
.ToString;
Character.Y is a string.
The error:
Cannot convert method group "ToString" to non-delegate type "string".
Anyone have tips or a solution?
Use parenthesis to invoke/call a method:
expr.ToString()
Without parenthesis it (ToString) is treated as a "method group", which is useful in some cases - but not here.
As written, you are trying to treat a function ToString as a type string.
As the comment mentioned, you probably meant to write ToString().

Categories

Resources