Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Java to C#

Java to C#

Scheduled Pinned Locked Moved C#
csharpjavahelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zoomlion
    wrote on last edited by
    #1

    I have the following classes in Java which i want to convert to C# but have errors with the undelined codes. (Can someone help me with the C# equivalent of PUT and GET) class TagInfo{ public int tagOffset; public int tagLength; public TagInfo(){ } } private void buildMetaData() { Record record = getData(); int offset = IMGREC_TAGLIST_INDEX; int numTags = 0 ; short tagID = 0; try { numTags = this.getNumberOfTags() ; for (int i=0; i < numTags; i++){ TagInfo info = new TagInfo(); info.tagOffset = offset; info.tagLength = TagRecord.TAG_DATA_INDEX + record.readInt(offset + TagRecord.TAG_DATALEN_INDEX); tagID = record.readShort(offset + TagRecord.TAG_ID_INDEX); offset += info.tagLength; tagInfo.put(new Short(tagID),info); Console.WriteLine("tagID = " + tagID); } } catch (Exception ex) { } finally { } this.imageOffset = offset; this.imageSize = record.getLength() - offset; } public TagRecord getTagByID(short id) { TagRecord record = null; TagInfo info = (ImageRecord.TagInfo)tagInfo.get(new Short(id)); if (info != null){ byte[] data = this.getData().read(info.tagOffset,info.tagLength); record = new TagRecord(data); } return record; }

    L T 2 Replies Last reply
    0
    • Z Zoomlion

      I have the following classes in Java which i want to convert to C# but have errors with the undelined codes. (Can someone help me with the C# equivalent of PUT and GET) class TagInfo{ public int tagOffset; public int tagLength; public TagInfo(){ } } private void buildMetaData() { Record record = getData(); int offset = IMGREC_TAGLIST_INDEX; int numTags = 0 ; short tagID = 0; try { numTags = this.getNumberOfTags() ; for (int i=0; i < numTags; i++){ TagInfo info = new TagInfo(); info.tagOffset = offset; info.tagLength = TagRecord.TAG_DATA_INDEX + record.readInt(offset + TagRecord.TAG_DATALEN_INDEX); tagID = record.readShort(offset + TagRecord.TAG_ID_INDEX); offset += info.tagLength; tagInfo.put(new Short(tagID),info); Console.WriteLine("tagID = " + tagID); } } catch (Exception ex) { } finally { } this.imageOffset = offset; this.imageSize = record.getLength() - offset; } public TagRecord getTagByID(short id) { TagRecord record = null; TagInfo info = (ImageRecord.TagInfo)tagInfo.get(new Short(id)); if (info != null){ byte[] data = this.getData().read(info.tagOffset,info.tagLength); record = new TagRecord(data); } return record; }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Those lines appear to be using a variable which does not exist. What is the type of tagInfo and where does it come from? It isn't a local variable or parameter or even a field in the class - so what is it?

      1 Reply Last reply
      0
      • Z Zoomlion

        I have the following classes in Java which i want to convert to C# but have errors with the undelined codes. (Can someone help me with the C# equivalent of PUT and GET) class TagInfo{ public int tagOffset; public int tagLength; public TagInfo(){ } } private void buildMetaData() { Record record = getData(); int offset = IMGREC_TAGLIST_INDEX; int numTags = 0 ; short tagID = 0; try { numTags = this.getNumberOfTags() ; for (int i=0; i < numTags; i++){ TagInfo info = new TagInfo(); info.tagOffset = offset; info.tagLength = TagRecord.TAG_DATA_INDEX + record.readInt(offset + TagRecord.TAG_DATALEN_INDEX); tagID = record.readShort(offset + TagRecord.TAG_ID_INDEX); offset += info.tagLength; tagInfo.put(new Short(tagID),info); Console.WriteLine("tagID = " + tagID); } } catch (Exception ex) { } finally { } this.imageOffset = offset; this.imageSize = record.getLength() - offset; } public TagRecord getTagByID(short id) { TagRecord record = null; TagInfo info = (ImageRecord.TagInfo)tagInfo.get(new Short(id)); if (info != null){ byte[] data = this.getData().read(info.tagOffset,info.tagLength); record = new TagRecord(data); } return record; }

        T Offline
        T Offline
        The Man from U N C L E
        wrote on last edited by
        #3

        Not to good at Java, but my understanding is that Put and Get operate on an automaticaly generated parent hashtable of the object in question. c# does not have this at all. You have to create your own dictionary. This might not be quite right as you did not post the entier code, but the following should help you. Note the dictionary declaration and add/get code. I have used a generic dictionary to enable strong typing.

        class TagInfo{
        public int tagOffset;
        public int tagLength;

        public TagInfo(){
        }
        

        }

        // Dictionary to hold Taginfo Objects
        System.Collections.Generic.Dictionary; TagInfoDictionary = new System.Collections.Generic.Dictionary();

        private void buildMetaData()
        {

        Record record = getData();
        int offset = IMGREC\_TAGLIST\_INDEX;
        int numTags = 0 ;
        short tagID = 0;
        
        try
        {
        	numTags = this.getNumberOfTags() ;
        
        	for (int i=0; i < numTags; i++){
        		TagInfo info = new TagInfo();
        
        		info.tagOffset = offset;
        		info.tagLength = TagRecord.TAG\_DATA\_INDEX + record.readInt(offset + TagRecord.TAG\_DATALEN\_INDEX);
        		tagID = record.readShort(offset + TagRecord.TAG\_ID\_INDEX);
        		offset += info.tagLength;
        
        		//	Add to the dictionary
        		this.TagInfoDictionary.Add(tagID, info);
        
        		Console.WriteLine("tagID = " + tagID);
        	}
        }catch (Exception ex){}
        finally{}
        
        this.imageOffset = offset;
        this.imageSize = record.getLength() - offset;
        

        }

        public TagRecord getTagByID(short id)
        {
        TagRecord record = null;

        //	Get from dictionary
        TagInfo info = this.TagInfoDictionary\[id\];
        if (info != null){
        	byte\[\] data = this.getData().read(info.tagOffset,info.tagLength);
        	record = new TagRecord(data);
        }
        
        return record;
        

        }

        If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups