将C程序转换为C#

时间:2016-05-11 05:22:13

标签: c#

我在c#中编写Horspool算法。我有一个相同的c程序。我已经转换了大部分代码,但在转换代码的几行时遇到了一些困难。

我无法弄清楚如何转换的代码行是

#define MAX 500
int t[MAX]

char src[100],p[100];
int pos;
clrscr();
printf("Enter the text in which pattern is to be searched:\n");
gets(src);

任何人都可以告诉我如何将这些行转换为c#?

我的C程序代码的来源是 - http://www.c-program-example.com/2011/10/c-program-to-search-perticulur-pattern.html

1 个答案:

答案 0 :(得分:3)

#define MAX 500将是const int MAX = 500;

要在数组定义中使用MAX,您可以使用以下内容:

int[] t = new int[MAX];

您要转换为C#的行将如下所示:

string src;
string p;
int pos;
Console.Clear();
Console.WriteLine("Enter the text in which pattern is to be searched:\n");
src = Console.ReadLine();