I want to make sure that if the subs value is not equal to ", then UL go before and after it and to the sL variable. If subs is" ", then sL will get the value" "
var sL = (subs != "") ? "<ul>" + subs + "</ul>" : "";
But that does not work.
Is my format correct?
If in doubt, add additional brackets:
var sL = subs != "" ? ("<ul>" + subs + "</ul>") : "";
However, your code should work fine; this syntax is beautiful.
Susan, your code is correct and it works. I just tested in LinqPad. Perhaps your ss variable is null, not empty. I recommend you change your line to:
var sL = !string.IsNullOrEmply(subs) ? "<ul>" + subs + "</ul>" : "";
It should be the same:
if (subs != "") { sL = "<ul>" + subs + "</ul>"; } else { sL = ""; }
If this is what you are aiming for, then I would surround "<ul>" + subs + "</ul>" in brackets, just to make sure that the compiler understands what you want.
"<ul>" + subs + "</ul>"
I copied pasta'd your code and it worked perfectly on my machine.
Perhaps the problem is elsewhere?
Aside, rather use string.IsNullOrEmpty over = ""
string.IsNullOrEmpty
= ""
var sL = !string.IsNullOrEmpty(subs) ? "<ul>" + subs + "</ul>" : string.Empty;
Another option that no one has mentioned is to use string.Concat instead of + , for example:
string.Concat
+
var sL = (subs != "") ? string.Concat("<ul>", subs, "</ul>") : "";
If subs is ", then sL also becomes". "You just use the shortened version of if. What you wrote is exactly the same as
string sL; if (subs != ""){ sL = "<ul>" + subs + "</ul>"; }else{ sL = ""; }
Source: https://habr.com/ru/post/896481/More articles:Pidev says "Unauthorized import" error - pydevDoes GDB support "run-time sampling" or is there a custom extension? - profilingBased on the dictionary, find all possible letter options - language-agnostichttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/896479/scala-actors-what-happens-to-unread-inbox-messages&usg=ALkJrhjkfELrnwVU3bnzVGcSGnClPNGNWAMethod override for changing return type - c #display CENTERED series of images - cssFinding an unsigned 128-bit integer data type for the .NET Framework - c #View an ActivityGroup switch with animation - androidDataType to store a long serial number (10 bytes) - c #C #: System.Diagnostics.Process.Start ("Explorer.exe", @ "/ select" + FilePath). Cannot open file when file name is Unicode character - c #All Articles