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 am uploading files to a database and the method checks to make sure the correct file type is uploaded. If i check for each MIME type individually, it works fine, but when placed inside an OR it triggers the error.
if (formFile.ContentType != "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
{
modelState.AddModelError(formFile.Name,
$"The {fieldDisplayName}file ({fileName}) is not a valid file type.");
}
The above works fine, but when i add multiple filetypes(see below), it does not work
if (formFile.ContentType != "application/vnd.openxmlformats-officedocument.wordprocessingml.document" || formFile.ContentType != "text/plain")
{
modelState.AddModelError(formFile.Name,
$"The {fieldDisplayName}file ({fileName}) is not a valid file type.");
}
I know this will be something simple, i am just not seeing it.
The OR is working correctly. The issue is that you want to use a logical AND (&&).
It seems like you made a mistake.
Basic usage
if(True or True) {
// TRUE
}
Your usage
if(!True or !True) {
// False
}
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 1 year ago.
Improve this question
I'm trying to check specific folder exists. For example, checking folder named "Downloads" exists. I'm writing using C# Windows Forms app and this is code:
//key = Folder Name
{
var pathtu = Convert.ToBoolean(Directory.EnumerateDirectories(main,key,SearchOption.AllDirectories));
if (pathtu == true)
{
path[0] = #"c:\Users\"+key;
File.Move(file.SelectedPath, path[0]);
label2.Visible = true;
}
When I run this code I get the following error:
System.InvalidCastException: 'Unable to cast object of type 'System.IO.FileSystemEnumerableIterator`1[System.String]' to type 'System.IConvertible'.'
What am I doing incorrectly?
Use
Directory.Exists(pathtodir)
It returns a bool.
See https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.exists
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.
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 does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
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.
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.
Improve this question
I have a bit of a problem with my c# code.
I have a while loop:
while(current.parent != null)
{
solution.Add(current.move);
current = current.parent;
}
All of the variables have values, but for some reason it doesn't enter the while. I placed a break at the while and see that the parent property is not null, but it just skips the entire while.
Any ideas why? or how I can modify this to work?
Because current.parent is null to begin with.
Probably because current is the top most in your tree, i.e. has no children. (Or whatever you want to call it)
The code in your question is very vague but I would guess just using
solution.Add(current.move);
while(current.parent != null)
{
current = current.parent;
solution.Add(current.move);
}
may help.
This may solve the actual problem you are having (other than not knowing how to use a debugger ;))
So here you log the current move always, then log any parent moves.
Maybe look at refactoring this with a do..while loop!!
After seeing that every node in the tree had a null value (but the properties of the node weren't), I changed everything to work with the Node's properties instead, which finally worked.
Thanks guys =)
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