A discussion earlier today led me to question whether or not my understanding of primtives and literals is correct.
My understanding is that a literal type is specifically a type which can have a value assigned using a notation that both human and compiler can understand without specific type declarations:
var firstName = "John"; // ...
Wrapper class are just fine and their purpose is also well understood. But why do we omit the primitive type ?
...
I have a mutable class that I'm using as a key to a generic dictionary. Two keys should be equal only if their references are equal.
From what I've read, in this case, I don't need to override Equals, GetHashCode , or implement IEqualityComparer.
Is this correct?
...
Is there any way to return a readonly instance of an object?
public class Person
{
public String FirstName { get; set; }
public String LastName { get; set; }
}
public class SomeClass
{
public SomeClass(Person manager)
{
if (manager == null)
throw new ArgumentNullException("manager");
_manage...
Why is string a reference type, even though it's normally primitive data type such as int, float, or double.
...
For example, if I want to call the following:
person.Head.Nose.Sniff()
then if I want to be safe I have to do the following:
if(person != null)
if(person.Head != null)
if(person.Head.Nose != null)
person.Head.Nose.Sniff();
is there any easier way of formulating this expression?
...
I want to create a simple method that accepts both value type and reference type parameters, i.e. int is value, and string is reference.
So this is what I start with:
public bool areBothNotNull<T>(T? p1, T? p2)
{
return (p1.HasValue && p2.HasValue);
}
So I want to be able to use it like this:
var r1 = areBothNotNull<int>(3, 4);...