2011-12-13 67 views
-1
typedef struct WebBlocking { 
    char *protocal; 
    char *URL; 
    int Port; 
    int policy; 
} AllPolicy ; 

AllPolicy WebBlock[] = {{"HTTPS","accounts.google.com",40, 1},{"HTTP","yahoo",80, 1}, 
{"HTTP","www.facebook.com",80,1},{"HTTP","www.orkut.com",80,1}, 
{"HTTPS","login.yahoo.com",443, 2} }; 

# define NPolicy (sizeof WebBlock /sizeof (struct WebBlocking)) 

这个结构我想转换成C#...我想structers的数组传递给函数,如我用C这样做....C到C#皈依

bool Decompose_IpAdd ( struct WebBlocking POLICY[NPolicy], char * IpAddress ) 

我怎么能做到这一点在C#...我刚开始用C#编写...任何一个可以PLZ帮我把这段代码转换...

预先感谢您

回答

3

试试像这样:

public class WebBlocking 
{ 
    string protocol; 
    string url; 
    int port; 
    int policy; 
} 

WebBlocking[] array = new WebBlocking[4] { 

    new WebBlocking() { protocol = "https", url = "www...", port = 80, policy = 10 }, 
    new WebBlocking() { protocol = "https", url = "www...", port = 80, policy = 10 }, 
    new WebBlocking() { protocol = "https", url = "www...", port = 80, policy = 10 }, 
    new WebBlocking() { protocol = "https", url = "www...", port = 80, policy = 10 } 

}; 

然后到数组传递给你的函数做:

Decompose_IpAdd(array); 

我希望我理解正确你的问题。

+0

感谢ü上午......但如何将这种阵列结构的传递给函数.. –

+0

@ user1068804,在C#你不具备的功能。你只有方法。你究竟想要做什么。也许如果你解释更多,那么我可以给你一个更好的答案。 – Roman

+0

@Am。 - 在C#中,我们没有功能? – vidit