C# question!

Results 1 to 4 of 4
  1. #1
    Member Restitive is offline
    MemberRank
    Aug 2012 Join Date
    39Posts

    C# question!

    Hey.

    I have a question about this code :

    string text = (string)dataRow["Id"];
    this.Models.Add(text, new RoomModel(text, (int)dataRow["door_x"], (int)dataRow["door_y"], (double)dataRow["door_z"], (int)dataRow["door_dir"], (string)dataRow["heightmap"], (string)dataRow["public_items"], GoldTree.smethod_3(dataRow["club_only"].ToString())));
    And i have set in my database the id off room_models to INT so string gives an error in my emu.

    How can i set the (string)dataRow["Id"]; code to an (int)dataRow["Id"];
    Because i get an error when i do this in C#

    Greatz


  2. #2
    Check http://arcturus.pw The General is offline
    DeveloperRank
    Aug 2011 Join Date
    7,613Posts

    Re: C# question!

    Is 'text' even used. It is declared but if it is not used I don't see why you would use that.

    Also you can simply do string text = (int)dataRow["id"] + ""; (Append int to empty string)

    But, don't change your database structure unless you're sure it is REALLY needed.

  3. #3
    Evil Italian Overlowrd Droppy is offline
    Grand MasterRank
    Feb 2012 Join Date
    /home/droppyLocation
    2,080Posts

    Re: C# question!

    Follow:
    Code:
    int text = Int32.Parse((string)dataRow["Id"]);
    this.Models.Add((string)text, new RoomModel((string)text, (int)dataRow["door_x"], (int)dataRow["door_y"], (double)dataRow["door_z"], (int)dataRow["door_dir"], (string)dataRow["heightmap"], (string)dataRow["public_items"], GoldTree.smethod_3(dataRow["club_only"].ToString())));
    The dictionary is string, RoomModel, as I can tell looking at this code (except you are trying to fix it), so if you want to change that, you would have to follow the this.Model dictionary, change string to int, but it is unrecommended - it may give you error of string to int conversion, or others. Be aware.

  4. #4
    Member Restitive is offline
    MemberRank
    Aug 2012 Join Date
    39Posts

    Re: C# question!

    Ty for the comments :)
    I gonna look what is the best way to use..



Advertisement