Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Desktop Developer

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Visual Studio Async CTP videosThe Like keyword in VB.Net and the equivalent in C# »
    comments

    Introduction

    One of the big differences between C# and VB.Net is the fact that VB.Net is case insensitive and C# isn't.

    The case-insensitivity of VB.Net is sometimes weird and can lead to unwelcome side effects. Like you will see.

    Partial classes

    For example. the following is completely legal in VB.Net

    1. Module Module1
    2.  
    3.     Sub Main()
    4.         Dim t = New Test
    5.         t.Test()
    6.         t.partialtest()
    7.         Dim t2 = New test
    8.         t2.Test()
    9.         t2.partialtest()
    10.         Console.ReadLine()
    11.     End Sub
    12.    
    13. End Module
    14.  
    15. Public Class test
    16.     Public Sub Test()
    17.         Console.WriteLine("test")
    18.     End Sub
    19. End Class
    20.  
    21. Partial Public Class Test
    22.     Public Sub partialtest()
    23.         Console.WriteLine("partialtest")
    24.     End Sub
    25. End Class

    Watch the casing of the classes.

    See the instantiations?

    In C# we would use it like this.

    1. using System;
    2.  
    3. namespace ConsoleApplication1
    4. {
    5.     class Program
    6.     {
    7.         static void Main(string[] args)
    8.         {
    9.             var t = new ConsoleApplication2.test();
    10.             t.Test();
    11.             t.partialtest();
    12.             Console.ReadLine();
    13.         }
    14.  
    15.    }
    16. }

    In other words the name and casing of the class not the partial one. It won't work with the partial one.

    So next time they try to convert your VB.Net code to C# they will have a problem with all the different casings and none of it will really work and if your code is big enough it will even hardly make sense.

    WHY?????

    The question begs of course, why would you do this?? You don't!! But when you rename your class via Visual studio or just by deleting and retyping the characters than the partial class will not be renamed and in most cases you will not even notice because the partial class is in another file.

    Conclusion

    Be very careful with this kind of unwanted behavior you could upset someone.

    About the Author

    User bio imageChris is awesome.
    Social SitingsTwitterHomePageLTD RSS Feed
    c#, vb.net
    InstapaperVote on HN

    No feedback yet

    Leave a comment


    Your email address will not be revealed on this site.

    To mislead the spambots.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)