So when i try and use it in the constructor it gives an error (its null), this didn't happen in .Net 4 so im wondering if its a Core feature or .Net 5, any ideas?
I just tested this code in Console apps targeting .NET Framework 4.8 and .NET 5.0:
C#:
class Program
{
static void Main()
{
var t1 = new Thing();
var t2 = new Thing();
Console.WriteLine(t1.Name);
Console.WriteLine(t2.Name);
Console.ReadLine();
}
}
class Thing
{
private static int Count = 0;
public readonly string Name;
public Thing()
{
Count++;
Name = Count.ToString();
}
}
In both cases, it worked exactly the same way and exactly as you'd expect. I suspect that there's something else going on in your project and you just haven't debugged properly. As suggested, an int can't be null so, at the very least, your description is inaccurate.
I just tested this code in Console apps targeting .NET Framework 4.8 and .NET 5.0:
C#:
class Program
{
static void Main()
{
var t1 = new Thing();
var t2 = new Thing();
Console.WriteLine(t1.Name);
Console.WriteLine(t2.Name);
Console.ReadLine();
}
}
class Thing
{
private static int Count = 0;
public readonly string Name;
public Thing()
{
Count++;
Name = Count.ToString();
}
}
In both cases, it worked exactly the same way and exactly as you'd expect. I suspect that there's something else going on in your project and you just haven't debugged properly. As suggested, an int can't be null so, at the very least, your description is inaccurate.
Yes you are of course correct. When stepping through the code last night that was the line which seemed to throw the error, look at it this morning and realised its actually a line where its trying to get a cursor.
this line below was failing not entirely sure why as it was ok previously
C#:
private static Cursor handleCursor = new Cursor(typeof(DrawPolygon), "PolyHandle.cur");
replaced it with the next line after adding the cursor to resources and all is working again.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.