Which language solution in C # annoys you?

I was just dealing with strings, and I find myself annoyed that strings can be nullified. So I have to have

if((teststring??string.Empty)==string.Empty) 

everywhere. Will there be a line? were so difficult that they allowed invalidation in a relatively small number of cases when it was necessary (dbs, idiotic user inputs, etc.). I am also annoyed that I have to export read-only interfaces when I need some form of const matching. So, what C # wording / solution annoys you?

EDIT: Thanks for the inexperienced function, I have not seen this before! However, I do not reduce my frustration when it is reset: D

+7
c #
source share
13 answers

Creating a string of a reference type seems to me quite reasonable.

It’s a shame that you cannot declare the type of the variable / parameter / return value non-zero (for example,

 // Never returns null public string! Foo() { } 

The code contracts in .NET 4.0 will help with this, I suppose - but it's a bit late to make it ubiquitous.

Some time ago I wrote a blog post about C # errors . To summarize this post:

C # 1:

  • Lack of shared access for getter / setter for properties.
  • Lack of generics. From the very beginning, life would be much sweeter with generics.
  • Classes do not close by default.
  • Enumerates only names.
  • The character sequence "\ x".
  • Various things about switch statement :)
  • Some rules for odd congestion resolution
  • Keyword "lock" instead of "use" with tocken locking.

C # 2:

  • Lack of partial methods (included in C # 3)
  • Lack of total variance (included in C # 4)
  • System.Nullable class (not Nullable<T> - that's great!)
  • InternalsVisibleTo requires the entire public key for strictly signed assemblies instead of the public key token.

C # 3:

  • Lack of immutability support - many changes have improved the capabilities for mutable types (automatic properties, initializers of objects and collections), but none of them really work for mutable types
  • Extension Method Detection
+21
source share

String testing for Null or Empty is best used using:

 if (string.IsNullOrEmpty(testString)) { } 
+28
source share

Probably the biggest sparkling hole in C # for me is the listing.

Java variables are type classes that you can give so that they can implement interfaces, etc.

FROM#/. Pure enumerations are simply glorified ints with all the problems that int constants returned to C and C ++.

+6
source share

out and ref parameters

+5
source share

Mitch's answer extension.

This is actually a CLR solution, not C #. C # has no control over the implementation details of the BCL System.String class.

True C # may have a special line string in the compiler and said that we will do special checks, but it would be IMHO, it was a bad decision. String.IsNullOrEmpty is an acceptable compromise.

+1
source share

Filling a gap in a non-empty case.

Verbosity of transfers, especially in the case of statements. If I have switch (expr) and expr is an enumeration, I should not be forced to fully qualify each enumeration in each case, if there is no name conflict.

+1
source share

Checked exceptions would be great. I know that many people hate them from Java, but I think this always led to a sanity check, especially on I / O. I like most of the things C # has changed and / or added compared to Java, but I really would like them to accept checked exceptions. Too late (the .NET framework has changed so that they can break almost every program), but I think it would be better to have them.

+1
source share

How should I implement properties from an interface in C # 3.0, although they are exactly the same as the interface when I do not change the default behavior for auto properties.

eg.

 public interface MyInterface { int MyProperty { get; set;} } public class MyClass : MyInterface { public int MyProperty { get; set; } } public class MyClass2 : MyInterface { public int MyProperty { get; set; } } public class MyClass3 : MyInterface { public int MyProperty { get; set; } } 

EDIT: To review some of the comments on this. I do not change the default behavior of my recipient. I understand the difference between a class and an interface thankyou, I want to say that I mark it with an interface that I should not have this property inside each implementation class if I do not want to change the default behavior for getter or setter. Imagine 500 classes implementing this interface?

Also disadvantage of Mixins ..

0
source share

Do not allow sharing changes or changing access rights when redefining a base class or interface implementation methods:

 public class A { protected virtual Stream method() { //...stuff... } } public class B : A { // compiler borks... public override FileStream method() { //...more stuff... } } 
0
source share

I don't like typing IEnumerable<MyType> everywhere. Its so hard to read. I would prefer some kind of short hand to make my code cleaner.

This SO post sums up.

0
source share

I find it extremely annoying that many basic methods are static, especially around commonly used materials such as strings and arrays.

Why:

 Array.Sort(myArray); String.IsNullOrEmpty(myString); 

instead:

 myArray.Sort(); myString.IsNullOrEmpty 

Not to say that there is no good reason for this, and this is not very important, but if JS can do this, why can C # not? *

A switch implementation is also implemented. I really think they should have trusted us with failure.

* Come to the point that I also skipped JS closure syntax.

0
source share

I don't like IDisposable / Dispose etc. Coming from C ++, this is very annoying when you have to think about memory management in C #. The using statement is great if a one-time object is used in only one function. If it needs to be transferred, you need to manually calculate the bill or do something else to know when you can dispose of the facility.

0
source share

I would like to see class objects as first class objects in the language.

This will allow you to override static methods and declare them in interfaces.

0
source share

All Articles