The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Here's a (big, bad) difference between VB.NET and C#

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Frans Bouma

Posts: 265
Nickname: fbouma
Registered: Aug, 2003

Frans Bouma is a senior software engineer for Solutions Design
Here's a (big, bad) difference between VB.NET and C# Posted: Nov 12, 2003 2:59 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Frans Bouma.
Original Post: Here's a (big, bad) difference between VB.NET and C#
Feed Title: Frans Bouma's blog
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/fbouma/Rss.aspx
Feed Description: Generator.CreateCoolTool();
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Frans Bouma
Latest Posts From Frans Bouma's blog

Advertisement

Ricardo blogs about the differences between C# and VB.NET. Well, I'll give you one, which is very harmful in some areas.

Class C is a derived class from DataTable. DataTable implements ISerializable, but does this private. Class C has a new member variable which has to be serialized as well. Simply adding '[Serializable]' to Class C doesn't work, because a base class already implements ISerializable. So C has to implement ISerializable too.

Because DataTable implements ISerializable private (ISerializable.GetObjectData() is private), this can be a problem, since I have to do the complete serialization of C and the data in its base class by hand. Dino Esposito wrote an article about that, it's located here.

Using Dino's article, I can implement ISerializable and the GetObjectData() code to serialize the data and the private membervariable of C. That is... in C#. In VB.NET you can't, because the VB.NET compiler will throw an error that a base class of C already implements ISerializable. There is no way in VB.NET to re-implement ISerializable or to make the serialization formatter call a GetObjectData() method defined in C to do the serialization, simply because it will see the GetObjectData() method of DataTable as the implementation of ISerializable.GetObjectData(), which will serialize the DataTable contents, but not private member variables of derived classes.

Now, it took me some time to work around this (create a C# class with the member variable, derive the VB.NET class from that class) and it still isn't a solution which will work in all cases. In other words: VB.NET lacks re-implementation of interface members and with classes like DataTable in .NET (some winforms controls also have some interface members implemented privately, so you can't re-implement them) which have a privately implemented ISerializable, VB.NET can be a struggle in some situations, so be careful which language to pick for some of your classes.

Read: Here's a (big, bad) difference between VB.NET and C#

Topic: ClickOnce and "locked down" systems Previous Topic   Next Topic Topic: Geek Notes 2003-11-10

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use