[{"data":1,"prerenderedAt":568},["ShallowReactive",2],{"blogvbnet-to-c-conversion":3,"blogMore-Development":554,"comments-vbnet-to-c-conversion":567},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"category":11,"tags":12,"excerpt":16,"body":44,"_type":545,"_id":546,"_source":547,"_file":548,"_stem":549,"_extension":550,"url":551,"wordCount":552,"minutes":188,"commentCount":553},"/blog/2005/2005-08-08-vbnet-to-c-conversion","2005",false,"en","VB.NET to C# conversion","I recently converted some components on a project from VB.NET to C#, mainly for overloading and better tool support (such as ReSharper). Some of the existing code was generated from my own CodeSmith templates, so a small rewrite to generate C# handled most of that.","2005-08-08T02:00:00+00:00","Development",[13,14,15],".NET","C#","VB.NET",{"type":17,"children":18},"root",[19,35],{"type":20,"tag":21,"props":22,"children":23},"element","p",{},[24,27,29,31,33],{"type":25,"value":26},"text","I recently converted some components on a project from VB.NET to C#, mainly for overloading and better tool support (such as ",{"type":25,"value":28},"ReSharper",{"type":25,"value":30},"). Some of the existing code was generated from my own ",{"type":25,"value":32},"CodeSmith",{"type":25,"value":34}," templates, so a small rewrite to generate C# handled most of that.",{"type":20,"tag":21,"props":36,"children":37},{},[38,40,42],{"type":25,"value":39},"The remaining code, while not extensive in size, is a rather complex affair and the prospect of debugging this code when hand-converted was a little daunting so I decided to give the demo version of VBConversion’s ",{"type":25,"value":41},"VB.NET to C# Converter 1.31",{"type":25,"value":43}," a spin.",{"type":17,"children":45,"toc":536},[46,66,72,83,97,104,227,232,308,313,319,324,330,335,341,346,397,402,447,453,458,521,530],{"type":20,"tag":21,"props":47,"children":48},{},[49,50,58,59,65],{"type":25,"value":26},{"type":20,"tag":51,"props":52,"children":56},"a",{"href":53,"rel":54},"https://www.jetbrains.com/resharper/",[55],"nofollow",[57],{"type":25,"value":28},{"type":25,"value":30},{"type":20,"tag":51,"props":60,"children":63},{"href":61,"rel":62},"https://www.codesmithtools.com",[55],[64],{"type":25,"value":32},{"type":25,"value":34},{"type":20,"tag":67,"props":68,"children":70},"h2",{"id":69},"vbnet-to-c-converter-131",[71],{"type":25,"value":41},{"type":20,"tag":21,"props":73,"children":74},{},[75,76,82],{"type":25,"value":39},{"type":20,"tag":51,"props":77,"children":80},{"href":78,"rel":79},"https://www.vbconversions.com",[55],[81],{"type":25,"value":41},{"type":25,"value":43},{"type":20,"tag":21,"props":84,"children":85},{},[86,88,95],{"type":25,"value":87},"I was disappointed it made some obvious and stupid mistakes especially when it had converted everything else so well; so much for the 99% accuracy claim. I thought it might just be our project be we adhere to many of ",{"type":20,"tag":51,"props":89,"children":92},{"href":90,"rel":91},"https://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconnetframeworkdesignguidelines.asp",[55],[93],{"type":25,"value":94},"Microsoft’s guidelines",{"type":25,"value":96},"…",{"type":20,"tag":98,"props":99,"children":101},"h3",{"id":100},"problem-1-ignores-all-instanceclass-variables-default-assignments-and-constructors",[102],{"type":25,"value":103},"Problem 1: Ignores all instance/class variables default assignments and constructors.",{"type":20,"tag":105,"props":106,"children":111},"pre",{"className":107,"code":108,"language":109,"meta":110,"style":110},"language-vb shiki shiki-themes everforest-light dracula","Public Class Mine\n  Public myObj As MyClass = New MyClass()\n  Private myVar As MyEnumeration = MyEnumeration.MyDefault\nEnd Class\n","vb","",[112],{"type":20,"tag":113,"props":114,"children":115},"code",{"__ignoreMap":110},[116,140,186,218],{"type":20,"tag":117,"props":118,"children":121},"span",{"class":119,"line":120},"line",1,[122,128,134],{"type":20,"tag":117,"props":123,"children":125},{"style":124},"--shiki-default:#F57D26;--shiki-dark:#FF79C6",[126],{"type":25,"value":127},"Public",{"type":20,"tag":117,"props":129,"children":131},{"style":130},"--shiki-default:#3A94C5;--shiki-dark:#FF79C6",[132],{"type":25,"value":133}," Class ",{"type":20,"tag":117,"props":135,"children":137},{"style":136},"--shiki-default:#5C6A72;--shiki-dark:#F8F8F2",[138],{"type":25,"value":139},"Mine\n",{"type":20,"tag":117,"props":141,"children":143},{"class":119,"line":142},2,[144,149,154,159,165,170,175,181],{"type":20,"tag":117,"props":145,"children":146},{"style":124},[147],{"type":25,"value":148},"  Public",{"type":20,"tag":117,"props":150,"children":151},{"style":136},[152],{"type":25,"value":153}," myObj ",{"type":20,"tag":117,"props":155,"children":156},{"style":124},[157],{"type":25,"value":158},"As",{"type":20,"tag":117,"props":160,"children":162},{"style":161},"--shiki-default:#3A94C5;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic",[163],{"type":25,"value":164}," MyClass",{"type":20,"tag":117,"props":166,"children":167},{"style":124},[168],{"type":25,"value":169}," =",{"type":20,"tag":117,"props":171,"children":172},{"style":130},[173],{"type":25,"value":174}," New ",{"type":20,"tag":117,"props":176,"children":178},{"style":177},"--shiki-default:#8DA101;--shiki-dark:#50FA7B",[179],{"type":25,"value":180},"MyClass",{"type":20,"tag":117,"props":182,"children":183},{"style":136},[184],{"type":25,"value":185},"()\n",{"type":20,"tag":117,"props":187,"children":189},{"class":119,"line":188},3,[190,195,200,204,209,213],{"type":20,"tag":117,"props":191,"children":192},{"style":124},[193],{"type":25,"value":194},"  Private",{"type":20,"tag":117,"props":196,"children":197},{"style":136},[198],{"type":25,"value":199}," myVar ",{"type":20,"tag":117,"props":201,"children":202},{"style":124},[203],{"type":25,"value":158},{"type":20,"tag":117,"props":205,"children":206},{"style":161},[207],{"type":25,"value":208}," MyEnumeration",{"type":20,"tag":117,"props":210,"children":211},{"style":124},[212],{"type":25,"value":169},{"type":20,"tag":117,"props":214,"children":215},{"style":136},[216],{"type":25,"value":217}," MyEnumeration.MyDefault\n",{"type":20,"tag":117,"props":219,"children":221},{"class":119,"line":220},4,[222],{"type":20,"tag":117,"props":223,"children":224},{"style":130},[225],{"type":25,"value":226},"End Class\n",{"type":20,"tag":21,"props":228,"children":229},{},[230],{"type":25,"value":231},"Suddenly becomes;",{"type":20,"tag":105,"props":233,"children":237},{"className":234,"code":235,"language":236,"meta":110,"style":110},"language-csharp shiki shiki-themes everforest-light dracula","public class Mine {\n  public MyClass myObj;\n  private MyEnumeration myVar;\n}\n","csharp",[238],{"type":20,"tag":113,"props":239,"children":240},{"__ignoreMap":110},[241,266,283,300],{"type":20,"tag":117,"props":242,"children":243},{"class":119,"line":120},[244,249,255,261],{"type":20,"tag":117,"props":245,"children":246},{"style":124},[247],{"type":25,"value":248},"public",{"type":20,"tag":117,"props":250,"children":252},{"style":251},"--shiki-default:#F85552;--shiki-dark:#FF79C6",[253],{"type":25,"value":254}," class",{"type":20,"tag":117,"props":256,"children":258},{"style":257},"--shiki-default:#3A94C5;--shiki-dark:#8BE9FD",[259],{"type":25,"value":260}," Mine",{"type":20,"tag":117,"props":262,"children":263},{"style":136},[264],{"type":25,"value":265}," {\n",{"type":20,"tag":117,"props":267,"children":268},{"class":119,"line":142},[269,274,278],{"type":20,"tag":117,"props":270,"children":271},{"style":124},[272],{"type":25,"value":273},"  public",{"type":20,"tag":117,"props":275,"children":276},{"style":161},[277],{"type":25,"value":164},{"type":20,"tag":117,"props":279,"children":280},{"style":136},[281],{"type":25,"value":282}," myObj;\n",{"type":20,"tag":117,"props":284,"children":285},{"class":119,"line":188},[286,291,295],{"type":20,"tag":117,"props":287,"children":288},{"style":124},[289],{"type":25,"value":290},"  private",{"type":20,"tag":117,"props":292,"children":293},{"style":161},[294],{"type":25,"value":208},{"type":20,"tag":117,"props":296,"children":297},{"style":136},[298],{"type":25,"value":299}," myVar;\n",{"type":20,"tag":117,"props":301,"children":302},{"class":119,"line":220},[303],{"type":20,"tag":117,"props":304,"children":305},{"style":136},[306],{"type":25,"value":307},"}\n",{"type":20,"tag":21,"props":309,"children":310},{},[311],{"type":25,"value":312},"While the object not being created will soon throw an exception, the defaults for value types is a little harder to track down.",{"type":20,"tag":98,"props":314,"children":316},{"id":315},"problem-2-gives-up-on-select-case-statements-after-the-first-case-commenting-out-the-others",[317],{"type":25,"value":318},"Problem 2: Gives up on Select Case statements after the first case, commenting out the others.",{"type":20,"tag":21,"props":320,"children":321},{},[322],{"type":25,"value":323},"In at least one case it got so confused it commented out substantially more code after the case statement too.",{"type":20,"tag":98,"props":325,"children":327},{"id":326},"problem-3-declares-additional-unnecessary-name-spaces-including-the-one-for-microsoftvisualbasic-despite-not-needing-it",[328],{"type":25,"value":329},"Problem 3: Declares additional unnecessary name-spaces including the one for Microsoft.VisualBasic, despite not needing it.",{"type":20,"tag":21,"props":331,"children":332},{},[333],{"type":25,"value":334},"Either we hadn’t used the CDate/CInt/CLng functions or it had converted them)…",{"type":20,"tag":98,"props":336,"children":338},{"id":337},"problem-4-all-with-statements-are-converted-to-be-variable-with1-even-when-the-old-with-clause-was-a-simple-case",[339],{"type":25,"value":340},"Problem 4: All with statements are converted to be variable with1, even when the old with clause was a simple case.",{"type":20,"tag":21,"props":342,"children":343},{},[344],{"type":25,"value":345},"For example:",{"type":20,"tag":105,"props":347,"children":349},{"className":107,"code":348,"language":109,"meta":110,"style":110},"With myObj\n  .doThis()\nEnd With\n",[350],{"type":20,"tag":113,"props":351,"children":352},{"__ignoreMap":110},[353,366,383],{"type":20,"tag":117,"props":354,"children":355},{"class":119,"line":120},[356,361],{"type":20,"tag":117,"props":357,"children":358},{"style":251},[359],{"type":25,"value":360},"With",{"type":20,"tag":117,"props":362,"children":363},{"style":136},[364],{"type":25,"value":365}," myObj\n",{"type":20,"tag":117,"props":367,"children":368},{"class":119,"line":142},[369,374,379],{"type":20,"tag":117,"props":370,"children":371},{"style":136},[372],{"type":25,"value":373},"  .",{"type":20,"tag":117,"props":375,"children":376},{"style":177},[377],{"type":25,"value":378},"doThis",{"type":20,"tag":117,"props":380,"children":381},{"style":136},[382],{"type":25,"value":185},{"type":20,"tag":117,"props":384,"children":385},{"class":119,"line":188},[386,392],{"type":20,"tag":117,"props":387,"children":389},{"style":388},"--shiki-default:#8DA101;--shiki-dark:#8BE9FD",[390],{"type":25,"value":391},"End",{"type":20,"tag":117,"props":393,"children":394},{"style":251},[395],{"type":25,"value":396}," With\n",{"type":20,"tag":21,"props":398,"children":399},{},[400],{"type":25,"value":401},"becomes;",{"type":20,"tag":105,"props":403,"children":405},{"className":234,"code":404,"language":236,"meta":110,"style":110},"MyClass with1 = myObj;\nwith1.doThis();\n",[406],{"type":20,"tag":113,"props":407,"children":408},{"__ignoreMap":110},[409,430],{"type":20,"tag":117,"props":410,"children":411},{"class":119,"line":120},[412,416,421,426],{"type":20,"tag":117,"props":413,"children":414},{"style":161},[415],{"type":25,"value":180},{"type":20,"tag":117,"props":417,"children":418},{"style":136},[419],{"type":25,"value":420}," with1 ",{"type":20,"tag":117,"props":422,"children":423},{"style":124},[424],{"type":25,"value":425},"=",{"type":20,"tag":117,"props":427,"children":428},{"style":136},[429],{"type":25,"value":282},{"type":20,"tag":117,"props":431,"children":432},{"class":119,"line":142},[433,438,442],{"type":20,"tag":117,"props":434,"children":435},{"style":136},[436],{"type":25,"value":437},"with1.",{"type":20,"tag":117,"props":439,"children":440},{"style":177},[441],{"type":25,"value":378},{"type":20,"tag":117,"props":443,"children":444},{"style":136},[445],{"type":25,"value":446},"();\n",{"type":20,"tag":67,"props":448,"children":450},{"id":449},"using-both-vbnet-and-c-together",[451],{"type":25,"value":452},"Using both VB.NET and C# together",{"type":20,"tag":21,"props":454,"children":455},{},[456],{"type":25,"value":457},"If you are going to use both in a project you can bring the syntax a little closer in format, here’s a few tips.",{"type":20,"tag":459,"props":460,"children":461},"ul",{},[462,468,501,506,511,516],{"type":20,"tag":463,"props":464,"children":465},"li",{},[466],{"type":25,"value":467},"Don’t use the Visual Basic CInt/CDate/IsNumber etc functions. Use the .NET Framework equivalents such as Int.Parse, Date.Parse etc. which will work in both languages and are normally faster than these legacy functions.",{"type":20,"tag":463,"props":469,"children":470},{},[471,473],{"type":25,"value":472},"Bring the source closer together by;\n",{"type":20,"tag":459,"props":474,"children":475},{},[476,481,486,491,496],{"type":20,"tag":463,"props":477,"children":478},{},[479],{"type":25,"value":480},"Putting brackets round if conditions in VB.NET",{"type":20,"tag":463,"props":482,"children":483},{},[484],{"type":25,"value":485},"Putting quotes round region declarations in C#",{"type":20,"tag":463,"props":487,"children":488},{},[489],{"type":25,"value":490},"Putting attributes on separate lines in VB.NET with a _ suffix",{"type":20,"tag":463,"props":492,"children":493},{},[494],{"type":25,"value":495},"Dropping the implementation and interface declarations onto a new line in C#",{"type":20,"tag":463,"props":497,"children":498},{},[499],{"type":25,"value":500},"Dropping the base(whatever) onto a new line in C# constructors (good idea anyway)",{"type":20,"tag":463,"props":502,"children":503},{},[504],{"type":25,"value":505},"Check out the “Differences Between Visual Basic .NET and Visual C# .NET” white paper on MSDN",{"type":20,"tag":463,"props":507,"children":508},{},[509],{"type":25,"value":510},"Use VBCommenter to get C# style XML comment documentation.",{"type":20,"tag":463,"props":512,"children":513},{},[514],{"type":25,"value":515},"Use Monitor.Enter() instead of VB.NET's synclock and C#’s lock.",{"type":20,"tag":463,"props":517,"children":518},{},[519],{"type":25,"value":520},"Be aware of the differences regarding math! VB.NET defaults to floating point precision and rounding when converting with CInt/CLng etc.. C# normally uses integer division and casting truncates.",{"type":20,"tag":21,"props":522,"children":523},{},[524],{"type":20,"tag":525,"props":526,"children":527},"em",{},[528],{"type":25,"value":529},"[)amien",{"type":20,"tag":531,"props":532,"children":533},"style",{},[534],{"type":25,"value":535},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":110,"searchDepth":142,"depth":142,"links":537},[538,544],{"id":69,"depth":142,"text":41,"children":539},[540,541,542,543],{"id":100,"depth":188,"text":103},{"id":315,"depth":188,"text":318},{"id":326,"depth":188,"text":329},{"id":337,"depth":188,"text":340},{"id":449,"depth":142,"text":452},"markdown","content:blog:2005:2005-08-08-vbnet-to-c-conversion.md","content","blog/2005/2005-08-08-vbnet-to-c-conversion.md","blog/2005/2005-08-08-vbnet-to-c-conversion","md","/blog/2005/08/08/vbnet-to-c-conversion/",519,0,[555,559,563],{"title":556,"date":557,"url":558},"HTML5 Video Cheatsheet: Optimizing videos for the web","2025-12-05T00:00:00Z","/blog/2025/12/05/html5-video-cheatsheet/",{"title":560,"date":561,"url":562},"Transactions in the MongoDB EF Core Provider","2025-10-25","/blog/2025/10/25/mongodb-explicit-transactions/",{"title":564,"date":565,"url":566},"Queryable Encryption with the MongoDB EF Core Provider","2025-09-22","/blog/2025/09/22/mongodb-queryable-encryption/",[],1777844949384]