All Questions
111
questions
0
votes
1
answer
89
views
Convert string to C# Conditional operator [closed]
I'd like convert string to ConditionalOperator, few sample :
"and" to &&
"or" to ||
"greatherthan" to >=
"contains" to .Contains
Something like ...
1
vote
2
answers
315
views
.Net 7 - Null Conditional-Access Operator (?. or ?[]) Rules in Boolean Evaluations
I was wondering if someone has a documentation source or a good explanation for the exact rules/implementation of the interactions between a boolean-resulting operation and the null conditional-access ...
0
votes
1
answer
62
views
Bitewise And Operator
Wondering about the &= operator. And how it works. From what i have gathered it finds out the last "bit" and returns it. Like for example 10 in binary is 1010. So it will return 0.
What ...
6
votes
1
answer
554
views
Negating the 'is' operator with a variable only works with '!' but not with '== false'
Why does (expr is type varname) == false gives a compile error, but !(expr is type varname) compiles?
public static void Foo(object o)
{
if(!(o is string s)) // <-- Using '!'
{
...
0
votes
1
answer
268
views
Set 3 bits in the middle of the byte C# (bitwise operators)
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
byte value = 0;
value = SetValue(value,5,3,7);
Console....
0
votes
1
answer
139
views
What is better in practice, using ==/!= or is operator? [closed]
When checking a variable for being true, false, null, etc is there a performance difference in doing a check with the traditional logical operators like ==, != vs the is operator in C#? Outside of any ...
0
votes
0
answers
87
views
How can you apply '?' operator in c#?
Does c# distinguish all three of the following:
int? []arr; // array of nullable ints
int []?arr; // nullable array of ints
int? []?arr; // nullable array of nullable ints
0
votes
2
answers
94
views
Property/Accessor ambiguity when using Expression Body operators
Using C# (.Net 4.6), assuming this code:
public class test
{
private bool _a = true;
public test() { }
public bool a => _a;
}
Is the public bool a => _a; implementation the same ...
0
votes
0
answers
41
views
Implementing the not operator when using the is keyword in C#? [duplicate]
Is there anyway to implement a not ! operator in C# when using is keyword , for example if I have a class named Model , I can check in a list of Items for what items are of type Model similar to ...
0
votes
1
answer
109
views
Logic operations in string value which include symbols
I am trying to incorporate a conditional operation based of the value stored in a string variable.
For example out of a set of values I have , I am trying to implement it such that when the string ...
0
votes
1
answer
243
views
How can I subtract an object in dotnet core using the minus symbol? Similar to DateTime
DateTimes in dotnet can be subtracted from each other using the symbol (-) and getting a span as a result. How can I replicate the behavior of DateTime to use the - symbol but for my own custom object
...
-1
votes
2
answers
659
views
Null Conditional Operator should used until what? ?.ToString()?.Trim() etc [duplicate]
I have misunderstanding some of Null-conditional operator ?. mechanism
Example getting Length of String variable
object variable = null;
int? Length = variable?.ToString()?.Trim()?.Length;
Should ...
2
votes
3
answers
2k
views
How does increment operator work with arrays?
Here's code that confuses me:
var array = new int[5];
array[0] = 1;
array[0]++;
Console.WriteLine(array[0]); //'2' is printed
I don't understand why array's item got incremented. From my ...
7
votes
2
answers
4k
views
?? or .GetValueOrDefault() [closed]
I have properties type int? and decimal? that are being used in a calculation. If the value of any of them is null it has to default to 0. I'm trying to decide between using null-coalescing or ...
0
votes
2
answers
109
views
How to subtract a value from 2 text field and store the value in second text field?
I am having a project in which I have a fields like price, quantity, total amount , paid amount, pending amount & credit amount paid. Now the calculation for total amount is been done by using ...