Archive

Posts Tagged ‘.NET’

C# vs Java: casting objects and calling members

February 11th, 2011

Given these two functionally identical code samples in c# and java, what is the output?

C#:

public class A
{
  public String Method()
  {
    return "this is A";
  }
}

public class B : A
{
  public String Method()
  {
    return "this is B";
  }
}

A thisA = new B();

thisA.Method();

Java:

public class A
{
  public String Method()
  {
    return "this is A";
  }
}

public class B extends A
{
  public String Method()
  {
    return "this is B";
  }
}

A thisA = new B();

thisA.Method();

What does thisA.Method() return?

It turns out that there are two different answers to this. In .NET/C# it returns from A (“this is A”). In Java, it returns from B (“this is B”).

So far it appears that this is a type issue; new B() must be getting cast back to A in C#. Looking for some documentation on this specifically. Links anyone?

.NET, Interesting, Technology , ,

Coping contents of Template Column in data grid to clipboard

August 18th, 2010

There are some nice new features (coming from Silverlight 2) in the latest versions of Silverlight – being able to copy rows in a DataGrid via the familiar Control+C for instance.

But I noticed something strange: some columns were blank when I pasted them into Excel (or notepad). The blank columns were always DataGridTemplateColumn and that made sense. How could it know what to copy from one or more controls?

Turns out this is really easy to fix if you are using data binding. All you have to do is bind the ClipboardContentBinding property on the DataGridTemplateColumn with the value you want copied for this column.

For example:

1
2
3
4
5
6
7
<data:DataGridTemplateColumn Header="Name" ClipboardContentBinding="{Binding Name}" SortMemberPath="Name">
  <data:DataGridTemplateColumn.CellTemplate>
     <DataTemplate>
        <HyperlinkButton Content="{Binding Name}" Margin="3" />
     </DataTemplate>
  </data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>

And that’s it. Control+C copy works as desired.

.NET, Silverlight ,

CodeStock 2010: Chaos to Awesome

June 28th, 2010

We’ll be posting our notes and slidedeck a bit later, but here are some of the resources we talked about in the presentation.

VisualSVN Server: http://www.visualsvn.com/server/
Ankh SVN (plugin for Visual Studio): http://ankhsvn.open.collab.net/

Hudson Continuous Integration: http://hudson-ci.org/

Fitnesse (.NET/SLiM): http://www.fitnesse.org/ and http://www.fitnesse.org/FitNesse.DotNet

You can always message us on twitter @jwcarroll and @benfarmer.

.NET, Agile , ,