skip to Main Content

My below code worked fine while running in .NET 4.0 but when I run the same code in .NET 2.0 I am getting an error at var I found that var is not accepted in .NET 2.0 and older but my Plesk 9.0.1 do not allow me to use .NET 4.0 also I cannot upgrade my plesk at this time because of traffic to my server. Well, anybody please convert the below code such that is works even with .NET 2.0. Thanks in advance.

        var app = new hMailServer.Application();
        app.Authenticate("Administrator", "********");
        var domain = app.Domains.get_ItemByName("mydomain.ext");
        var account = domain.Accounts.Add();
        account.Address = "[email protected]";
        account.Password = "secret";
        account.Active = true;
        account.MaxSize = 1000;
        account.PersonFirstName = "";
        account.Save();

Just instead of var what can I use? I tried string which is not accepted. Any idea?

First line I used as hMailServer.Application app = new hMailServer.Application(); Its accepted bur at the var domain and var account .NET 2.0 is not accepting.

2

Answers


  1. Just instead of var what can I use?

    Use the actual types (read the documentation of the API you are using to understand what those types are):

    hMailServer.Application app = new hMailServer.Application();
    app.Authenticate("Administrator", "********");
    hMailServer.Domain domain = app.Domains.get_ItemByName("mydomain.ext");
    hMailServer.Account account = domain.Accounts.Add();
    ...
    

    Also note that var was introduced in C# 3.0 and not 4.0.

    Login or Signup to reply.
  2. Basically you need to identify the type of your variables and then declare them.. you could do it by hovering over the variable and visual studio should show you the return type or the type of variable it is.

    Or install Resharper (a productivity tool) for visual studio it should assist you with the same.. You can do things like pull out variable for a particular piece of code and it will take care of identifying the type etc of your varaible.. You should be able to get a trial version.

    You might have to do this en masse that is why I am suggesting this.

    P.S: I am not markerting Resharper.. just a regular user of the software and in awe of the same.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search