Click here to Skip to main content
15,846,091 members
Home / Discussions / C#
   

C#

 
GeneralRe: "the horror:" why does C# let me get away with this ? Pin
BillWoodruff15-Jan-23 18:13
professionalBillWoodruff15-Jan-23 18:13 
GeneralRe: "the horror:" why does C# let me get away with this ? Pin
lmoelleb18-Jan-23 0:10
lmoelleb18-Jan-23 0:10 
GeneralRe: "the horror:" why does C# let me get away with this ? Pin
jschell22-Jan-23 9:30
jschell22-Jan-23 9:30 
QuestionImageAnnotationDemo Pin
Rahmo14-Jan-23 23:50
Rahmo14-Jan-23 23:50 
AnswerRe: ImageAnnotationDemo Pin
Richard MacCutchan15-Jan-23 2:34
mveRichard MacCutchan15-Jan-23 2:34 
AnswerRe: ImageAnnotationDemo Pin
OriginalGriff15-Jan-23 2:41
mveOriginalGriff15-Jan-23 2:41 
Questionthe new Math.Generics ? Pin
BillWoodruff13-Jan-23 2:04
professionalBillWoodruff13-Jan-23 2:04 
GeneralRe: the new Math.Generics ? Pin
harold aptroot13-Jan-23 18:46
harold aptroot13-Jan-23 18:46 
I hadn't really used it yet (which may indicate something as well) but I briefly tried it just now, so keep in mind I don't really know my way around the API yet:
  • Large repertoire of available operations, which applies to .NET 7 broadly, not only generic math. Nice operations such as rotates, popcount, leading zero count, are no longer hidden away in weird corners of the language (or worse: absent - as they used to be).
  • Despite shift counts no longer needing to be int, shifting by T is not allowed. So while working with T, shifting by constants is fine (since they'd be int), but as soon as you want to shift by some value that comes out of a generic calculation.. well you still end up with some weird conversions. This also applies to the count parameter of rotates. This has anti-synergy with the return types of T.PopCount and T.TrailingZeroCount and so on, which return T. I definitely would want to write x >>> T.TrailingZeroCount(x) at some point, but no.
  • There is an explicit unsigned right shift, but >> means "either signed or unsigned right shift depending on the type". What if I want an explicit signed right shift, even if T is an unsigned type? E: in non-generic code of course the answer is "just cast to the corresponding signed type, shift, then cast back". But then in generic code the question is, what type is that? See one of the next points for the problem with that.
  • There is no easy way to get the number of bits in T. There are ways, sure, but I was hoping for T.BitSize or something like that. Do I really need to write T.PopCount(T.AllBitsSet)? Bonus: the result of that is a T but you probably want an int. Or x.GetByteCount() * 8 perhaps? (why do I need an instance x to find the byte count?)
  • There seems to be no way to express certain constraints on types such as "given some signed type TS, TU is the corresponding unsigned type of the same size". Well, I don't know how C# would do that. But I can do it in C++, and it would be useful. For example if I wanted to define a type-changing version of Abs, which takes a signed integer and returns an unsigned integer of the same size - as it is, I wouldn't be able to constrain the types to have the same size. As far as I know, anyway.
  • There are standard "low multiplications" that take two T and return the low half of the product as a T. Elsewhere in .NET classes, there are functions such as Math.BigMul that return the full product. Generic T has a lot of fancy operations defined for it, but not BigMul (nor a hypothetical HighMul that only returns the upper half of the product).
Well it seems useful overall, but with some annoyances.

E: a sneaky advantage of generic math is that it lets you negate unsigned integers (ie find their additive inverse) with a plain old negation, no nonsense such as 0 - x. Progress! You still can't write -someUlong in non-generic code though.

modified 14-Jan-23 1:46am.

AnswerRe: the new Math.Generics ? Pin
jschell15-Jan-23 9:09
jschell15-Jan-23 9:09 
QuestionVirtual USB Com port makes my C# control application freeze and crash when I single-step the microcontroller with the USB-device Pin
arnold_w13-Jan-23 2:04
arnold_w13-Jan-23 2:04 
AnswerRe: Virtual USB Com port makes my C# control application freeze and crash when I single-step the microcontroller with the USB-device Pin
Gerry Schmitz14-Jan-23 6:37
mveGerry Schmitz14-Jan-23 6:37 
SuggestionC# web page interaction Pin
Samar Shehzad12-Jan-23 19:48
Samar Shehzad12-Jan-23 19:48 
GeneralRe: C# web page interaction Pin
OriginalGriff12-Jan-23 19:56
mveOriginalGriff12-Jan-23 19:56 
GeneralRe: C# web page interaction Pin
Samar Shehzad12-Jan-23 19:58
Samar Shehzad12-Jan-23 19:58 
GeneralRe: C# web page interaction Pin
OriginalGriff12-Jan-23 20:26
mveOriginalGriff12-Jan-23 20:26 
GeneralRe: C# web page interaction Pin
Graeme_Grant12-Jan-23 20:59
mvaGraeme_Grant12-Jan-23 20:59 
AnswerRe: C# web page interaction Pin
Richard Deeming12-Jan-23 23:11
mveRichard Deeming12-Jan-23 23:11 
QuestionWhy isn't my semi-editable ComboBox drawing the text in gray when the dropdown list isn't showing? Pin
arnold_w10-Jan-23 3:25
arnold_w10-Jan-23 3:25 
AnswerRe: Why isn't my semi-editable ComboBox drawing the text in gray when the dropdown list isn't showing? Pin
OriginalGriff10-Jan-23 4:46
mveOriginalGriff10-Jan-23 4:46 
GeneralRe: Why isn't my semi-editable ComboBox drawing the text in gray when the dropdown list isn't showing? Pin
arnold_w10-Jan-23 5:06
arnold_w10-Jan-23 5:06 
GeneralRe: Why isn't my semi-editable ComboBox drawing the text in gray when the dropdown list isn't showing? Pin
Ralf Meier10-Jan-23 5:55
professionalRalf Meier10-Jan-23 5:55 
GeneralRe: Why isn't my semi-editable ComboBox drawing the text in gray when the dropdown list isn't showing? Pin
arnold_w10-Jan-23 6:21
arnold_w10-Jan-23 6:21 
GeneralRe: Why isn't my semi-editable ComboBox drawing the text in gray when the dropdown list isn't showing? Pin
Ralf Meier10-Jan-23 7:14
professionalRalf Meier10-Jan-23 7:14 
AnswerRe: Why isn't my semi-editable ComboBox drawing the text in gray when the dropdown list isn't showing? Pin
Pete O'Hanlon12-Jan-23 1:03
subeditorPete O'Hanlon12-Jan-23 1:03 
GeneralRe: Why isn't my semi-editable ComboBox drawing the text in gray when the dropdown list isn't showing? Pin
arnold_w12-Jan-23 3:29
arnold_w12-Jan-23 3:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.