Skip to main content
change misnomer (method header -> method attribute)
Source Link
sehe
  • 400.3k
  • 49
  • 475
  • 673

A couple of things I like:

-If you create an interface similar to

 public interface SomeObject<T> where T : SomeObject<T>, new() 

you force anything that inherits from this interface to contain a parameterless constructor. It is very useful for a couple of things I've run across.

-Using anonymous types to create a useful object on the fly:

var myAwesomeObject = new {Name="Foo", Size=10}; 

-Finally, many Java developers are familiar with syntax like:

public synchronized void MySynchronizedMethod(){} 

However, in C# this is not valid syntax. The workaround is a method headerattribute:

 [MethodImpl(MethodImplOptions.Synchronized)] public void MySynchronizedMethod(){} 

A couple of things I like:

-If you create an interface similar to

 public interface SomeObject<T> where T : SomeObject<T>, new() 

you force anything that inherits from this interface to contain a parameterless constructor. It is very useful for a couple of things I've run across.

-Using anonymous types to create a useful object on the fly:

var myAwesomeObject = new {Name="Foo", Size=10}; 

-Finally, many Java developers are familiar with syntax like:

public synchronized void MySynchronizedMethod(){} 

However, in C# this is not valid syntax. The workaround is a method header:

 [MethodImpl(MethodImplOptions.Synchronized)] public void MySynchronizedMethod(){} 

A couple of things I like:

-If you create an interface similar to

 public interface SomeObject<T> where T : SomeObject<T>, new() 

you force anything that inherits from this interface to contain a parameterless constructor. It is very useful for a couple of things I've run across.

-Using anonymous types to create a useful object on the fly:

var myAwesomeObject = new {Name="Foo", Size=10}; 

-Finally, many Java developers are familiar with syntax like:

public synchronized void MySynchronizedMethod(){} 

However, in C# this is not valid syntax. The workaround is a method attribute:

 [MethodImpl(MethodImplOptions.Synchronized)] public void MySynchronizedMethod(){} 
Minor edit: grammar/spelling/case/punctuation/etc.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

A couple of things I like:

-If you create an interface similar to:

 public interface SomeObject<T> where T : SomeObject<T>, new() 

you force anything that inherits from this interface to contain a parameterless constructor... It is very useful for a couple of things I've run across.

-Using anonymous types to create a useful object on the fly:

var myAwesomeObject = new {Name="Foo", Size=10}; 

-Finally, many Java developers are familiar with syntax like:

public synchronized void MySynchronizedMethod(){} 

howeverHowever, in C# this is not valid syntax. The workaround is a method header:

 [MethodImpl(MethodImplOptions.Synchronized)] public void MySynchronizedMethod(){} 

A couple things I like:

-If you create an interface similar to:

 public interface SomeObject<T> where T : SomeObject<T>, new() 

you force anything that inherits from this interface to contain a parameterless constructor... very useful for a couple things I've run across.

-Using anonymous types to create a useful object on the fly

var myAwesomeObject = new {Name="Foo", Size=10}; 

-Finally, many Java developers are familiar with syntax like

public synchronized void MySynchronizedMethod(){} 

however, in C# this is not valid syntax. The workaround is a method header:

 [MethodImpl(MethodImplOptions.Synchronized)] public void MySynchronizedMethod(){} 

A couple of things I like:

-If you create an interface similar to

 public interface SomeObject<T> where T : SomeObject<T>, new() 

you force anything that inherits from this interface to contain a parameterless constructor. It is very useful for a couple of things I've run across.

-Using anonymous types to create a useful object on the fly:

var myAwesomeObject = new {Name="Foo", Size=10}; 

-Finally, many Java developers are familiar with syntax like:

public synchronized void MySynchronizedMethod(){} 

However, in C# this is not valid syntax. The workaround is a method header:

 [MethodImpl(MethodImplOptions.Synchronized)] public void MySynchronizedMethod(){} 
Minor edit: grammar/spelling/case/punctation/etc.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

A couple things I like:

-If you create an interface similar to:

 public interface SomeObject<T> where T : SomeObject<T>, new() 

you force anything that inherits from this interface to contain contain a parameterless constructor... very useful for a couple couple things I've run across.

-Using anonymous types to create a useful object on the fly

var myAwesomeObject = new {Name="Foo", Size=10}; 

-Finally, many javaJava developers are familiar with syntax like

public synchronized void MySynchronizedMethod(){} 

however, in c#C# this is not valid syntax. The workaround is a method header:

 [MethodImpl(MethodImplOptions.Synchronized)] public void MySynchronizedMethod(){} 

A couple things I like:

-If you create an interface similar to:

 public interface SomeObject<T> where T : SomeObject<T>, new() 

you force anything that inherits from this interface to contain a parameterless constructor... very useful for a couple things I've run across.

-Using anonymous types to create a useful object on the fly

var myAwesomeObject = new {Name="Foo", Size=10}; 

-Finally, many java developers are familiar with syntax like

public synchronized void MySynchronizedMethod(){} 

however, in c# this is not valid syntax. The workaround is a method header:

 [MethodImpl(MethodImplOptions.Synchronized)] public void MySynchronizedMethod(){} 

A couple things I like:

-If you create an interface similar to:

 public interface SomeObject<T> where T : SomeObject<T>, new() 

you force anything that inherits from this interface to contain a parameterless constructor... very useful for a couple things I've run across.

-Using anonymous types to create a useful object on the fly

var myAwesomeObject = new {Name="Foo", Size=10}; 

-Finally, many Java developers are familiar with syntax like

public synchronized void MySynchronizedMethod(){} 

however, in C# this is not valid syntax. The workaround is a method header:

 [MethodImpl(MethodImplOptions.Synchronized)] public void MySynchronizedMethod(){} 
added 37 characters in body
Source Link
George Mauer
  • 122.9k
  • 140
  • 401
  • 632
Loading
Post Made Community Wiki by CommunityBot
Source Link
Bryan
  • 81
  • 1
  • 2
Loading