PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
2.0 Writing net 2.0 code ?-VBForums
Results 1 to 5 of 5

Thread: Writing net 2.0 code ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    425

    Writing net 2.0 code ?

    Suppose I have net 4.0 code:
    Code:
     
    var node = new TreeNode(rootDirectory["Name"].ToString()) { Tag = rootDirectory };
    I want to learn how to write net code 2.0 statement above how to rewrite ? Do you have a software name that converts net 2.0 code to net 4.0 or vice versa for ease of code lookup ?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,102

    Re: Writing net 2.0 code ?

    There is nothing in that line of code that would not work in a project targeting .NET 2.0. You clearly haven't even tried it for yourself or you'd already know that.

    You need to first understand the difference between the C# language and the .NET Framework. In this context, the .NET Framework is a type library. In each new version, new types were added to that library, new members were added to some types and various other changes occurred. Each version has release notes that includes a list of breaking changes but pretty much any code that worked in an old version will work in a newer version. If you want to use a type or member in an older version, simply look up the documentation for that type or member and it will tell you what .NET Framework versions support it. You only ever have to look for replacement types or members for those that exist in the newer version but not in the older one.

    The C# language is separate to the .NET Framework. If you are writing code in VS 2019 then you are using the latest version of the C# language so you can use all the features of that newest version, even if you're targeting an older version of the .NET Framework. For instance, that code uses an object initialiser. I can't recall what version introduced that language feature but, in earlier versions, you would have to set the property independently:
    csharp Code:
    1. var node = new TreeNode(rootDirectory["Name"].ToString());
    2.  
    3. node.Tag = rootDirectory;
    If you're using the latest version of C# then you can use that language feature even if you are targeting a version of the .NET Framework that was released before that language feature existed.

    There is no tool that I've ever heard of that would do such a "conversion". As I said, code written to target .NET 2.0 should just work as is when used to target .NET 4.0. It's possible that you will get some warnings in a newer IDE that is more stringent when validating syntax and it is also possible that you'll get the occasional error, but there will be so few that fixing them manually will not be difficult. There may also be some things that could be done better with newer language and Framework features, but it's up to you whether you want to make those changes or not. If you change the Framework version in a project and go from 4.0 to 2.0, it's quite possible that everything will still work there too. Any types or members not supported will be flagged by the compiler and you can address each one manually, asking on this site if you can't handle any particular issues.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    425

    Re: Writing net 2.0 code ?

    I do not use net 2.0, my accounting program uses net 2.0, I learn code 2.0 and net code 4.0, I want to convert net 2.0 code to net 4.0, of course net 2.0 code still runs in VS2015, I want to learn to convert code, I need code conversion software to look up the code so that the program is more compact and faster.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,102

    Re: Writing net 2.0 code ?

    Quote Originally Posted by dong View Post
    I want to learn to convert code
    There is no "conversion" to be done. As you said, code that runs under .NET 2.0 also runs under .NET 4.0 so it already IS .NET 4.0 code. If you want to optimise your code for .NET 4.0 then by all means do so, but there isn't necessarily only one way to do that.
    Quote Originally Posted by dong View Post
    I need code conversion software to look up the code so that the program is more compact and faster.
    No such software exists. Are you a developer or not? If you are, write the code. If not, what are you doing here? The "code conversion tool" is inside your head so try putting it to work. If you know how to write code to target .NET 4.0 then all you need to do is analyse the existing code to determine what it is actually doing from a functionality perspective and then ask yourself whether there is a better way to implement that same functionality using .NET 4.0. Of course, much of the new functionality available in .NET 4.0 won't make your application any faster. It simply makes the code easier to write and read again. For example, using LINQ may actually make your app run slower but it may well make your code more readable and thus more maintainable in the future. Which is more important to you and, even if more readable is better, is it better enough to warrant the time and effort to rewrite that part of the code? These are all things that you need to apply some brain power to instead of assuming that some magic conversion tool will abdicate you of responsibility.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    425

    Re: Writing net 2.0 code ?

    Reading your post, I found that it is not easy and fast to convert the code for the program, I will slowly edit any code I know and I understand them when I have free time. Thank you so much for reading my post

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width