New answers tagged

4

C doesn't offer custom namespaces as C++ does, but it's untrue that C doesn't have namespaces at all. Functions and structures are in different namespaces: #include <stdio.h> void Test ( ) { printf("Hello World\n"); } struct Test { int field1; int field2; }; int main ( ) { struct Test t = { 0, 1 }; Test(); return 0; } When ...


1

To be more precise at the valid values: they have to have 5 or 6 digits. The first 4 can have any value between 1000 and 9999, the remaining digit(s) are either between 1 and 4 or 1 and 12 Given these requirements, one way to solve this specifically with C# is to use a struct, but to take into account that all types in .NET are zero-initialised. To work ...


2

In a comment, you wrote with a struct I didn't need to explicitely implement equality and I didn't have to do null checks. Therefore I'd prefer a struct. If the requirement is just to wrap an int, implementing equality in a class should be pretty trivial. And for avoiding null checks, I think your best bet is to use the new C# 8.0 feature "Nullable ...


3

You need a requirements review. Not every integer value is valid This is a very weak requirement. There is no computer in existence for which this isn't true. Some ints are so long they'd fill up your HD. So having this requirement here doesn't help much. Consider restating what this was meant to say or removing this entirely. The valid ...


Top 50 recent answers are included