Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C C#
Im trying to modify a C code into C# and Im stuck here:
typedef struct { char index; char f; char g; char k; } todo;
 
static const todo for4[] = {
  {0,2,15,4} , {0,3,5,1} , {0,3,25,11} , {0,5,9,3}
, {0,5,21,9} , {0,7,15,7} , {0,8,15,8} , {0,10,9,8}
, {0,10,21,14} , {0,12,5,10} , {0,12,25,20} , {0,13,15,15}
, {0,15,1,15} , {0,15,11,17} , {0,15,19,21} , {0,15,29,29}
, {3,1,3,0} , {3,1,27,12} , {3,4,3,1} , {3,4,27,13}
, {3,6,7,3} , {3,6,13,5} , {3,6,17,7} , {3,6,23,11}
, {3,9,7,6} , {3,9,13,8} , {3,9,17,10} , {3,9,23,14}
, {3,11,3,8} , {3,11,27,20} , {3,14,3,13} , {3,14,27,25}
, {4,2,1,0} , {4,2,11,2} , {4,2,19,6} , {4,2,29,14}
, {4,7,1,3} , {4,7,11,5} , {4,7,19,9} , {4,7,29,17}
, {4,8,1,4} , {4,8,11,6} , {4,8,19,10} , {4,8,29,18}
, {4,13,1,11} , {4,13,11,13} , {4,13,19,17} , {4,13,29,25}
, {7,1,5,0} , {7,1,25,10} , {7,4,5,1} , {7,4,25,11}
, {7,5,7,2} , {7,5,13,4} , {7,5,17,6} , {7,5,23,10}
, {7,10,7,7} , {7,10,13,9} , {7,10,17,11} , {7,10,23,15}
, {7,11,5,8} , {7,11,25,18} , {7,14,5,13} , {7,14,25,23}
, {9,2,9,1} , {9,2,21,7} , {9,3,1,0} , {9,3,11,2}
, {9,3,19,6} , {9,3,29,14} , {9,7,9,4} , {9,7,21,10}
, {9,8,9,5} , {9,8,21,11} , {9,12,1,9} , {9,12,11,11}
, {9,12,19,15} , {9,12,29,23} , {9,13,9,12} , {9,13,21,18}
, {10,2,5,0} , {10,2,25,10} , {10,5,1,1} , {10,5,11,3}
, {10,5,19,7} , {10,5,29,15} , {10,7,5,3} , {10,7,25,13}
, {10,8,5,4} , {10,8,25,14} , {10,10,1,6} , {10,10,11,8}
, {10,10,19,12} , {10,10,29,20} , {10,13,5,11} , {10,13,25,21}
, {13,1,15,3} , {13,4,15,4} , {13,5,3,1} , {13,5,27,13}
, {13,6,5,2} , {13,6,25,12} , {13,9,5,5} , {13,9,25,15}
, {13,10,3,6} , {13,10,27,18} , {13,11,15,11} , {13,14,15,16}
, {13,15,7,15} , {13,15,13,17} , {13,15,17,19} , {13,15,23,23}
, {14,1,7,0} , {14,1,13,2} , {14,1,17,4} , {14,1,23,8}
, {14,4,7,1} , {14,4,13,3} , {14,4,17,5} , {14,4,23,9}
, {14,11,7,8} , {14,11,13,10} , {14,11,17,12} , {14,11,23,16}
, {14,14,7,13} , {14,14,13,15} , {14,14,17,17} , {14,14,23,21}
} ;
 
It looks like a delegate function of sort but Im not sure how I could translate the code into C#. I have read this:
http://msdn.microsoft.com/en-us/library/05w82thz%28v=vs.71%29.aspx[^]
 
But still cant wrap my head around how to do it in C#.
 

BTW: There are several simular tables with other eaqualy sized arrays named:
static const todo for6[] = {...
static const todo for12[] = {...
Posted 15-Sep-12 7:08am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This code should get you going in the right direction :
 
public class todo
    {
        public char index;
        public char f;
        public char g;
        public char k;
    }
 
    public class A{
        static readonly todo[] for4 = 
          new todo[]{new todo(){index='a',f='a',g='a',k='a'},
                                                 
                     new todo(){index = (char)1,f='a',g='a',k='a'}
        };
    }
 
Some shortcuts are possible by providing a constructor to the todo class so that you don't have to name each member in its construction as it is in my example.
I provided one element as (char)1 to show how to use numbers like in your code.
  Permalink  
v2
Comments
Kenneth Haugland at 15-Sep-12 16:12pm
   
Almost there I guess, so typdef works in this case like a delegate to a List?
Philip Stuyck at 15-Sep-12 16:42pm
   
A c# delegate to me is a pointer to a method. A typedef in C or C++ is just something for the compiler it does not introduce any code nor does it introduce a new type. In C they usually do typedef struct blabla name; I don't like this syntax, and usually do struct name{blabla}. It is the struct keyword that introduces the new type not the typedef.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 741
1 OriginalGriff 255
2 Volynsky Alex 205
3 Kishore Pogaru 130
4 Magic Wonder 129
0 OriginalGriff 5,705
1 Sergey Alexandrovich Kryukov 4,763
2 CPallini 4,570
3 George Jonsson 3,142
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 15 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100