It's not often I find a truly interesting blog post on C#...
-
Some interesting things in there, even though I've never learned C#. But this came as a surprise:
Quote:
I’ve discovered this language feature by accident...
I hope the feature is documented instead of being an accidental side effect of the current implementation!
Robust Services Core | Software Techniques for Lemmings | Articles
-
Of course it's documented! It's documented right there in that blog post you just read! :laugh:
The author does actually suggest linking to his blog if your co-workers don't understand your code when it uses one of these spiffy features! :laugh:
Robust Services Core | Software Techniques for Lemmings | Articles
-
This: The Magical Methods in C# · Cezary Piątek Blog[^] is an exception.
Quote:
There’s a certain set of special method signatures in C# which have particular support on the language level. Methods with those signatures allow for using a special syntax which has several benefits. For example, we can use them to simplify our code or create DSL to express a solution to our domain-specific problem in a much cleaner way. I came across those methods in different places, so I decided to create a blog post to summarize all my discoveries on this subject.
Very cool.
Latest Articles:
Abusing Extension Methods, Null Continuation, and Null Coalescence OperatorsNice. I love it when I learn stuff.
Real programmers use butterflies
-
Nice. I love it when I learn stuff.
Real programmers use butterflies
honey the codewitch wrote:
Nice. I love it when I learn stuff.
I thought you might find that interesting. And yes, agreed! Learned new stuff!
Latest Articles:
Abusing Extension Methods, Null Continuation, and Null Coalescence Operators -
This: The Magical Methods in C# · Cezary Piątek Blog[^] is an exception.
Quote:
There’s a certain set of special method signatures in C# which have particular support on the language level. Methods with those signatures allow for using a special syntax which has several benefits. For example, we can use them to simplify our code or create DSL to express a solution to our domain-specific problem in a much cleaner way. I came across those methods in different places, so I decided to create a blog post to summarize all my discoveries on this subject.
Very cool.
Latest Articles:
Abusing Extension Methods, Null Continuation, and Null Coalescence Operators -
This: The Magical Methods in C# · Cezary Piątek Blog[^] is an exception.
Quote:
There’s a certain set of special method signatures in C# which have particular support on the language level. Methods with those signatures allow for using a special syntax which has several benefits. For example, we can use them to simplify our code or create DSL to express a solution to our domain-specific problem in a much cleaner way. I came across those methods in different places, so I decided to create a blog post to summarize all my discoveries on this subject.
Very cool.
Latest Articles:
Abusing Extension Methods, Null Continuation, and Null Coalescence Operators:thumbsup:
var errorCodes = new Dictionary { \[404\] = "Page not Found", \[302\] = "Page moved, but left a forwarding address.", \[500\] = "The web server can't come out to play today." };
that got my attention !
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
-
:thumbsup:
var errorCodes = new Dictionary { \[404\] = "Page not Found", \[302\] = "Page moved, but left a forwarding address.", \[500\] = "The web server can't come out to play today." };
that got my attention !
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
BillWoodruff wrote:
var errorCodes = new Dictionary<int, string> { [404] = "Page not Found", [302] = "Page moved, but left a forwarding address.", [500] = "The web server can't come out to play today." };
It's a syntactic side effect of the Add and Item methods. If you set a value of a dictionary via the Item method and the key doesn't exist the class will add the key and value. It is a very nice and clean way of writing:
var errorCodes = new Dictionary
{
{[404], "Page not Found"},
{[302], "Page moved, but left a forwarding address."},
{[500], "The web server can't come out to play today."}
};As I stated previously, there is nothing in this guy's blog that isn't directly the result of the C# and dotNet framework class documentation.
-
BillWoodruff wrote:
var errorCodes = new Dictionary<int, string> { [404] = "Page not Found", [302] = "Page moved, but left a forwarding address.", [500] = "The web server can't come out to play today." };
It's a syntactic side effect of the Add and Item methods. If you set a value of a dictionary via the Item method and the key doesn't exist the class will add the key and value. It is a very nice and clean way of writing:
var errorCodes = new Dictionary
{
{[404], "Page not Found"},
{[302], "Page moved, but left a forwarding address."},
{[500], "The web server can't come out to play today."}
};As I stated previously, there is nothing in this guy's blog that isn't directly the result of the C# and dotNet framework class documentation.
Who reads the entire documentation?
-
Who reads the entire documentation?
-
This: The Magical Methods in C# · Cezary Piątek Blog[^] is an exception.
Quote:
There’s a certain set of special method signatures in C# which have particular support on the language level. Methods with those signatures allow for using a special syntax which has several benefits. For example, we can use them to simplify our code or create DSL to express a solution to our domain-specific problem in a much cleaner way. I came across those methods in different places, so I decided to create a blog post to summarize all my discoveries on this subject.
Very cool.
Latest Articles:
Abusing Extension Methods, Null Continuation, and Null Coalescence OperatorsHe hints at it but doesn't show what you can do with the LINQ pattern. You can do fun stuff like this:
void Main()
{
var notACollection = new MyClass();
var x = from a in notACollection
where a.DoesntMatter == 5
select "Greetings Earthling";x.Dump(); // Prints "HELLO, WORLD!" } class MyClass { string \_msg; public int DoesntMatter; public MyClass Where(Func \_) { \_msg = "Hello, World!"; return this; } public string Select(Func \_) { return \_msg.ToUpperInvariant(); } }
Truth, James
-
This: The Magical Methods in C# · Cezary Piątek Blog[^] is an exception.
Quote:
There’s a certain set of special method signatures in C# which have particular support on the language level. Methods with those signatures allow for using a special syntax which has several benefits. For example, we can use them to simplify our code or create DSL to express a solution to our domain-specific problem in a much cleaner way. I came across those methods in different places, so I decided to create a blog post to summarize all my discoveries on this subject.
Very cool.
Latest Articles:
Abusing Extension Methods, Null Continuation, and Null Coalescence Operators