|
To be clear, I didn't want it to not compile. I actually wanted it to work if it didn't box.
Turns out i don't really need the check there anyway, I was primarily just seeing if it would work before i inserted it into my more complex routines that do batch copies of segments of the array.
What I wanted was to avoid doing things like calling Array.Clear unless it was a reference type but i wanted to check that without boxing. Unfortunately it boxes. That's okay for my methods where i must clear whole segments, but not where I'm clearing an individual item.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Is this new behavior?
I remember doing stuff like that and getting compile time errors saying T could be a value type which can never be null.
I've always had to add a class constraint.
|
|
|
|
|
It apparently depends on how you use it. It might be that the default(T) scenario is a special case.
Or maybe it works in comparisons but not assignments.
I don't know really, that's just casting the bones. But I do know in some cases you're right, it won't compile.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
honey the codewitch wrote: Or maybe it works in comparisons but not assignments. I think that's it.
Assignments can't be done, just as new T().
Perhaps you can work around boxing.[^]
public void MyVoid<T>(T something)
{
if (typeof(T).IsValueType)
{
}
else
{
}
} Although this is probably not about your code, but code others might possibly write?
|
|
|
|
|
I don't want to take the typeof hit either. I know metadata loading is fast but this was an optimization which would be killed by typeof
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Yeah, but maybe you have other reasons to avoid boxing
|
|
|
|
|
I prefer a battle of wits. Or a proper witchfight
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
|
|
Microsoft didn't document something ...and you're surprised at this?
|
|
|
|
|
Yes and no. They've generally done a fair to good job of specing out .NET and C#. Enough that this really frustrated me.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
So a friend asked me out to watch some local bands last night.
Sure, I'll go.
Didn't feel like going because it required me to leave the house, but I already said yes so let's get it over with.
When we're there, this girl walks up to my friend and apparently they knew each other.
So my friend asks her "how did it go?" (apparently, she just played on stage).
"I was so nervous. I like a bit of attention, but not like this. I'm never doing this again."
So I thought I'd try to be social and chime in, "try a beta blocker next time, it's a small pill and all your nerves will be gone."
I know because I use them when I have to do presentations.
Apparently, they're popular among students taking exams as well.
She looks me dead in the eye and says "I'd rather sniff something, but I've been clean for one and a half month now so I'm not taking anything."
Not the answer I was expecting.
Next time I'll just stand there and say nothing like I usually do
|
|
|
|
|
You need a reason not to talk to people? I don't.
|
|
|
|
|
Usually, no
|
|
|
|
|
In the music scene, you didn't expect singers to be snorting?
Such a sheltered life you have led!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I never said she was a singer
I live on an island with the nickname "the white island" (and not because its inhabitants are mainly white), but I've never known anyone who was on (hard) drugs. I think...
We have a lot of farmers who have sheds in the middle of nowhere, great for drug labs.
The musicians are all hobbyists, so they can't live the drugs, sex and rock n roll lifestyle in weekends and be at work/in school on Monday
|
|
|
|
|
Sander Rossel wrote: The musicians are all hobbyists, so they can't live the drugs, sex and rock n roll lifestyle in weekends and be at work/in school on Monday You would be surprised what can be done during the weekend and still be in the school on monday
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Yeah, but as you get older the possibilities become limited
|
|
|
|
|
I wouldn't say that... possibilities don't get limited.
But getting up on the next day gets worst, that's for sure...
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Quote: But getting up on the next day gets worst, that's for sure
But when you reach my age, you jump out of bed just to see the sun rise one more time!
|
|
|
|
|
If I had a party now as the ones I had 15 years ago... I would not jump out of the bed, I would be more than happy if I could crawl or roll out of it
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I don't even need to party for that... I am NOT a morning person...
|
|
|
|
|
This
|
|
|
|
|
Sander Rossel wrote: sheds in the middle of nowhere
In the Netherlands?
Didn't know you had such a thing.
Well, I suppose it's relative.
|
|
|
|
|
Well, "middle of nowhere" here means a five minute drive in each direction before you reach the next settlement...
But yeah, we must built more houses and move designated nature areas.
Because god forbid we have a square meter that's not house or asphalt.
I don't like vacations in the Netherlands, because no matter where you go you're never far from a busy road.
|
|
|
|