This question already has answers here:
What does question mark and dot operator ?. mean in C# 6.0?
(3 answers)
Closed 4 years ago.
I am new to my project, in the project they used Entity Framework & LINQ to
manipulate the DB data. Here I am not able to understand why the question mark (?) is used after get() method in the following query. Is it possible to use the (?) mark as like below ?. If yes, then could you please explain in detail.
uOW.ApplicationDetailsRepository.Get()?
.Where (x=>x.Name=="SomeConditions").Tolist();
When the question mark is used this way (in combination with the period: ?.), it is called the Null-conditional operator. It is a check for null before attempting the rest of the statement.
Here is a reference explaining in detail.
Related
This question already has answers here:
C# : 'is' keyword and checking for Not
(13 answers)
Closed 4 years ago.
To test if an object is of a certain type then we write if ( myObject is SomeClassName )
But how do we write if I want to test that the object is not of the mentionned type ?
if (!(myObject is SomeClassName))
Is probably the cleanest way of checking not is. Just checks if it is the type of object then flips it.
There isn't one, you have to wrap it in a ! operator:
if (!(myObject is SomeClassName))
This question already has answers here:
C# Empty Statement
(13 answers)
Closed 5 years ago.
I've come across this example of an empty statement in a C# textbook.
Code:
public void empty()
{
;
}
Some quick googling found that it's a redundant feature and I can't see the use of this as it seems pointless?
I was curious to know when this would've been useful and if it's still used to date even though it's obsolete?
In the given example it is pointless and/or cosmetic.
The empty statement is "useful" in places where a statement is required but you have nothing to do, like
while (condition_with_side_effects) ;
Because of the side effects required, this will not match with most coding guidelines or best practices.
Consider it a leftover from C.
This question already has answers here:
What's the difference between [Something] and [SomethingAttribute] [duplicate]
(3 answers)
Closed 7 years ago.
I hope this wasn't asked already. But i found nothing. If something exists, thanks for the note.
The title says it all i think.
I've seen these two variants. But in my opinion it does the same. And why can i use both. Thanks for education.
// variant 1
[ContentProperty("Text")]
// variant 2
[ContentPropertyAttribute("Text")]
You can omit the word "Attribute" when writing attributes over something. The actual class is called ContentPropertyAttribute. Both of your lines do exactly the same and use the exact same attribute class.
This question already has answers here:
What are attributes in .NET?
(11 answers)
Closed 9 years ago.
i've been developing in c# for 4 month and I still dont know what does the [] means in entity framework.
Here an example
[Column("mycolumn")]
public int Column {get;set;}
What is it functionality?
Its there another situation that i have to use it or just with entity framework?
Square brackets [ & ] mean a few different things in C#, but in this case they are saying that "Column" is an Attribute. An attribute is basically design time information that you add to classes or properties for various reasons. You can also make your own ;)
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
CompilerServices.Operators equivalent on C#
I was looking for Microsoft.CSharp.CompilerServices.Operators but couldn't find it.
No there is no real equivalent to this in the C# runtime assembly.
However many these methods are essentially implementing the late bound operations for VB.Net in a declarative method (and indeed there are cases where the late binder simply just defers to these methods for operations). So these could be replicated in C# by defining methods which just explicitly defer to the C# dynamic binder.
For example, the rough equivalent of DivideObject in C# would be the following
public static dynamic DivideObject(dynamic left, dynamic right)
{
return left / right;
}