Some C # operations seem unnecessarily cumbersome compared to other languages. For example lambdas:
students.GroupBy(student => student.State).Where(student => student.Count > 1).OrderByReversed(studentGroup => studentGroup.Count);
This can be shortened by using very short variable names:
students.GroupBy(s => s.State).Where(s => s.Count > 1).OrderByReversed(sg => sg.Count);
But in this way, variables are hard to understand out of context. Another way to shorten it is to simply skip the one-parameter listing completely, and the parameter should be implied by a dot:
students.GroupBy(.State).Where(.Count > 1).OrderByReversed(.Count);
For me it is a little readable than any of the above. This applies only to one-parameter lambdas, and, of course, this value is inferred from the context.
Edit: for lambdas where the parameter itself is used directly. 'can be used as a direct placeholder:
var lines = text.Split("\n").Where(line => line != "");
You can reduce it a bit using:
var lines = text.Split("\n").Where(. != "");
Another place this type of affiliate operator can use is in the Enum transmission. Often the enumeration name is passed too much when it is obvious from the context that it is. For example, working with OpenTK (implementation of OpenGL in C #), to create simple textures you need to call something like this every time:
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bd.Width, bd.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, myPointer); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
(Note that OpenTK.Graphics.OpenGL.PixelFormat must be passed with a full name, as it conflicts with System.Drawing.Imaging.PixelFormat using dot notation, this is no longer necessary)
This contains many enum enums, which in an equivalent C ++ implementation are much shorter and therefore easier to read at a glance. We could try to skip the names of the enumerations and get them out of context (parameter type of the called method):
GL.TexImage2D(.Texture2D, 0, .Rgba, bd.Width, bd.Height, 0, .Bgr, .UnsignedByte, myPointer); GL.TexParameter(.Texture2D, .TextureMinFilter, (int).Linear); GL.TexParameter(.Texture2D, .TextureMagFilter, (int).Linear);
This is not only short, but also shorter than the equivalent of C ++, which is easy to read, preserving the strongly typed character of the language. I am sure that there are other places where it can be used, these are just some syntax examples that I would like to see in the next version of C #. Do you think this would be a good idea?