C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,562 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I work on csharp i get error object reference not set to an instance of an object
so how to use Object.ReferenceEquals(null, myObjVar) to solve error
code give me error
var Data = result.items.Select(e => new { PartID = e.create._id, IsUpdated = e.create.error != null && e.create.error.reason !=null && !e.create.error.reason.Contains("document already exists") ? 0 : 1, ErrorStatus = e.create.error == null | (e.create.error.reason!=null && e.create.error.reason.Contains("document already exists")) ? null : e.create.error.reason }).ToList();
ElasticPartialUpdat.Create.error.get returned null.
How to use this lines below to solve error
if (Object.ReferenceEquals(null, myObjVar)) { ....... }
Here is an example which should help.
public class MonthData : IEquatable<MonthData>
{
public string Month { get; set; }
public int Index { get; set; }
public override string ToString()
{
return $"{{ Month = {Month}, Index = {Index} }}";
}
public bool Equals(MonthData other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Month == other.Month && Index == other.Index;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((MonthData) obj);
}
public override int GetHashCode()
{
return HashCode.Combine(Month, Index);
}
}
It's always good to read the docs