[不是问题] C#方法声明/创建的问题。 [英] [Not a question] Problems with C# methods declaration/ Creation.
本文介绍了[不是问题] C#方法声明/创建的问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码em试图在C#中转换C ++代码。但主要问题在于函数/方法。我很困惑如果有任何机构在这里清除我这些事情。谢谢
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
命名空间 tt
{
class 计划
{
静态 void Main( string [] args)
{
{
day b;
老师;
int x;
int y;
Console.WriteLine( / n,/ n,/ n,/ n) ;
Console.WriteLine( -----------------所有日子时间表------------------);
Console.WriteLine( / n,/ n,/ n,/ n) ;
Console.WriteLine( time-- 8.00 8.50 9.40 10.40 11.30 12.20 2.30);
Console.WriteLine( / n / n); //
Console.WriteLine( day / n); //
Console.WriteLine( | / n); //
Console.WriteLine( |); ///
Console.WriteLine( / n);
b.sun();
Console.WriteLine( / n,/ n,/ n);
b.mon();
Console.WriteLine( / n,/ n,/ n);
b.tue();
Console.WriteLine( / n,/ n,/ n);
b.wed();
Console.WriteLine( / n,/ n,/ n);
b.thu();
Console.WriteLine( / n,/ n,/ n);
Console.WriteLine( ****** END ******);
Console.WriteLine( / n,/ n,/ n);
Console.ReadKey();
Console.WriteLine( 您可以执行以下操作::输入适当的选项) ;
Console.WriteLine( / n,/ n,/ n);
Console.WriteLine( 例程仅一天);
Console.WriteLine( / n,/ n,);
Console.WriteLine(endl<< 1:sun);
Console.WriteLine( / n);
Console.WriteLine(endl<< 2:mon);
Console.WriteLine( / n);
Console.WriteLine(endl<< 3:tue<< endl ;
Console.WriteLine(endl<< 4:wed<< endl;
Console.WriteLine(endl<< 5:thu<< ; endl;
Console.WriteLine(endl<< 6:退出< < endl;
Console.WriteLine( / n,/ n,/ n );
Console.WriteLine( 如果您不需要一天的时间表,请输入:6);
Console.WriteLine( / n,/ n);
Console.WriteLine( 输入您的选择::);
Console.WriteLine ( / n,/ n,/ n);
Console.WriteLine( time --- 8.00 8.50 9.40 10.40 11.30 12.20 2.30) ;
Console.WriteLine( / n,/ n,/ n);
do
{
x = Convert.ToInt32(Console.ReadKey());
if (x> 5)
break ;
Console.WriteLine( / n,/ n);
开关(x)
{
case 1 :
b.sun();
break ;
case 2 :
b.mon();
break ;
case 3 :
b.tue();
break ;
case 4 :
b.wed();
break ;
case 5 :
b.thu();
break ;
默认:
break ;
}
Console.WriteLine( / n,/ n,/ n 跨度>);
} while (x< = 5 );
Console.WriteLine( 你想要老师安排:< /跨度>);
Console.WriteLine( / n,/ n,/ n);
Console.WriteLine( / n, 1:T-AJHER); //
Console.WriteLine(endl<< 2:T-NAWAJ << endl;
Console.WriteLine(endl<< 3: T-RAJIB<< endl;
Console.WriteLine(endl<< 4:T-SHABUR<< endl;
Console.WriteLine(endl<< 5:T-DABROTO<< endl;
Console.WriteLine(endl<< 6:T-JAHID<< endl;
Console.WriteLine(endl<< 7:T-ARIF<< endl ;
Console.WriteLine(endl<< 8:T-MORSHAD<< ; endl;
Console.WriteLine(endl<< 9:T-AGIJ << endl;
Console.WriteLine(endl<< 10:T-SULTAN<< endl;
Console.WriteLine(endl<< 11:T- LIAJE<< endl;
Console.WriteLine(endl<< 12 :T-MD.MOHAMOD<< endl;
Console.WriteLine(endl<< 13:退出;
Console.WriteLine(endl<< endl<< endl;
Console.WriteLine( 如果你不想要这个时间表输入:12);
Console.WriteLine( / n,/ n);
Console.WriteLine( 输入您的选择::;
控制台。 WriteLine( / n,/ n,/ n); // 少于12
做
{
y = Convert.ToInt32(Console.ReadKey());
if (y> 12)
中断;
Console.WriteLine( / n,/ n,/ n );
Console.WriteLine( time --- 8.00 8.50 9.40 10.40 11.30 12.20 2.30);
Console.WriteLine( / n,/ n,/ n );
switch (y)
{
case 1 :
s.t_AJHER();
break ;
case 2 :
s.t_NAWAJ();
break ;
case 3 :
s.t_RAJIB();
break ;
case 4 :
s.t_SHABUR();
break ;
case 5 :
s.t_DABROTO();
break ;
case 6 :
s.t_JAHID();
break ;
case 7 :
s.t_ARIF();
break ;
case 8 :
s.t_MORSHAD();
break ;
case 9 :
s.t_AGIJ();
break ;
case 10 :
s.t_SULTAN();
break ;
case 11 :
s.t_LIAJE();
case 12 :
s.t_MOHAMOD();
默认:
break ;
}
Console.WriteLine( / n,/ n,/ n);
}
while (x <= 12 );
Console.WriteLine( ----------------- --- ******** ********* END ------------------跨度>);
Console.ReadKey();
return 0 ;
}
}
class day
{
public sun()
{
Console.WriteLine( sun cse eee L cse(A-group);
Console.WriteLine( / n,/ n);
Console.WriteLine( RAJIB SHABUR AJHER & NAWAJ);
return 0 ;
}
mon()
{
Console.WriteLine( mon mat cse che eee L me1270);
Console.WriteLine( / n,/ n);
Console.WriteLine( JAHID AJHER MORSHAD DABROTO LIAJE& SULTAN);
return 0 ;
}
tue()
{
Console.WriteLine( tue mat che cse cse L cse(B-group));
Console.WriteLine( / n,/ n);
Console.WriteLine( ARIF AGIJ NAZRUL NAWAJ AJHER& ; NAWAJ);
return 0 ;
}
wed()
{
Console.WriteLine( wed - eeelab(A-group)----- cse eee Lab Hum);
Console.WriteLine( / N,/ N);
Console.WriteLine( SHABUR RAJIB DABROTO MD.MOHAMOD);
return 0 ;
}
thu()
{
Console.WriteLine( thu che cse mat ------ che(lab)-------- Leeelab(B-group));
Console.WriteLine( / n,/ n);
Console.WriteLine( MORSHAD RAJIB JAHID MORSHAD AJHER& NAWAJ);
return 0 ;
}
}
// ********** ********一天结束课程********************* //
// -------- ********************** - -------- //
class 老师
{
public t_AJHER()
{
Console.WriteLine( sun Lcse(A-group));
Console.WriteLine( / n,/ n);
Console.WriteLine( mon cse);
Console.WriteLine( / n,/ n);
Console.WriteLine( tue Lcse(B-group));
Console.WriteLine( / n,/ n);
return 0 ;
}
t_NAWAJ()
{
Console.WriteLine( sun Lcse(A_group));
Console.WriteLine( / n,/ n);
Console.WriteLine( tue cse Lcse(B-group));
Console.WriteLine( / n,/ n);
Console.WriteLine( thu cse);
Console.WriteLine( / n,/ n);
return 0 ;
}
t_RAJIB()
{
Console.WriteLine( cse);
Console.WriteLine( / n,/ n);
Console.WriteLine( tue cse);
Console.WriteLine( / n,/ n);
Console.WriteLine( wed cse);
Console.WriteLine( / n,/ n);
return 0 ;
}
t_SHABUR()
{
Console.WriteLine( sun eee);
Console.WriteLine( / n,/ n);
Console.WriteLine( wed -eeelab(A-group)---) ;
Console.WriteLine( / n,/ n);
Console.WriteLine( Leeelab(B-group));
Console.WriteLine( / n,/ n);
return 0 ;
}
t_DABROTO()
{
Console.WriteLine( mon eee);
Console.WriteLine( / n,/ n);
Console.WriteLine( wed eee);
Console.WriteLine( / n,/ n);
return 0 ;
}
t_JAHID()
{
Console.WriteLine( mon mat);
Console.WriteLine( / n,/ n);
Console.WriteLine( thu mat);
Console.WriteLine( / n,/ n);
return 0 ;
}
t_ARIF()
{
Console.WriteLine( tue mat);
Console.WriteLine(endl<< endl;
return 0 ;
}
t_MORSHAD()
{
Console.WriteLine( tue che);
Console.WriteLine( / n,/ n);
Console.WriteLine( thu che ------ che(lab) - --------);
Console.WriteLine( / n,/ n);
return 0 ;
}
t_AGIJ()
{
Console.WriteLine( mon che 跨度>);
Console.WriteLine( / n,/ n);
return 0 ;
}
t_LIAJE()
{
Console.WriteLine( mon L me1270-F,T);
Console.WriteLine( / n,/ n);
return 0 ;
}
t_SULTAN()
{
Console.WriteLine( mon L me1270-F,T);
Console.WriteLine( / n,/ n);
return 0 ;
}
t_MOHAMOD()
{
Console.WriteLine( Lab Hum);
return 0 ;
}
}
// ** ************************************************** **** //
// END TEACHER CLASS //
// ******************** *************************//
}
解决方案
而不是将C ++代码转换为C# [ ^ ],尝试了解它的作用。然后使用C#和.NET对象,方法等编写它。
这是一些有用的信息: C++ - > C#:从C ++迁移到C#需要了解的内容 [ ^ ]
首先明显。每个方法都应该有返回类型。
例如:
公共 sun()
应声明:
public int sun()
看起来你的方法总是返回0,但是你没有在代码中使用返回值。所以也许你应该考虑去除
返回0;行和声明你的方法如下:
public void sun()
现在尝试编译它,看看你得到了哪些其他错误
here is my code em trying to Convert C++ Code in C#. But the main prob is in Functions/Methods. i am confusing in If any body here to clear me these things. Thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace tt
{
class Program
{
static void Main(string[] args)
{
{
day b;
teacher s;
int x;
int y;
Console.WriteLine("/n,/n,/n,/n");
Console.WriteLine(" -----------------ALL DAY TIME SCHEDULE------------------");
Console.WriteLine("/n,/n,/n,/n");
Console.WriteLine("time-- 8.00 8.50 9.40 10.40 11.30 12.20 2.30");
Console.WriteLine("/n /n");//
Console.WriteLine("day /n");//
Console.WriteLine(" | /n") ;//
Console.WriteLine(" |");///
Console.WriteLine("/n");
b.sun();
Console.WriteLine("/n,/n,/n");
b.mon();
Console.WriteLine("/n,/n,/n");
b.tue();
Console.WriteLine("/n,/n,/n");
b.wed();
Console.WriteLine("/n,/n,/n");
b.thu();
Console.WriteLine("/n,/n,/n");
Console.WriteLine(" ******END****** ");
Console.WriteLine("/n,/n,/n");
Console.ReadKey();
Console.WriteLine("you can do the following::enter your appropriate option");
Console.WriteLine("/n,/n,/n");
Console.WriteLine("routine only a day ");
Console.WriteLine("/n,/n,");
Console.WriteLine(endl<<"1:sun");
Console.WriteLine("/n");
Console.WriteLine(endl<<"2:mon");
Console.WriteLine("/n");
Console.WriteLine(endl<<"3:tue"<<endl;
Console.WriteLine(endl<<"4:wed"<<endl;
Console.WriteLine(endl<<"5:thu"<<endl;
Console.WriteLine(endl<<"6:Quit"<<endl;
Console.WriteLine("/n,/n,/n");
Console.WriteLine("If you not need the one day schedule enter:6");
Console.WriteLine("/n,/n");
Console.WriteLine("Enter your choice::");
Console.WriteLine("/n,/n,/n");
Console.WriteLine("time--- 8.00 8.50 9.40 10.40 11.30 12.20 2.30");
Console.WriteLine("/n,/n,/n");
do
{
x = Convert.ToInt32( Console.ReadKey());
if(x>5)
break;
Console.WriteLine("/n,/n");
switch(x)
{
case 1:
b.sun();
break;
case 2:
b.mon();
break;
case 3:
b.tue();
break;
case 4:
b.wed();
break;
case 5:
b.thu();
break;
default:
break;
}
Console.WriteLine("/n,/n,/n");
}while(x<=5);
Console.WriteLine("Are you want the teacher schedule:");
Console.WriteLine("/n,/n,/n");
Console.WriteLine("/n","1:T-AJHER");//
Console.WriteLine(endl<<"2:T-NAWAJ"<<endl;
Console.WriteLine(endl<<"3:T-RAJIB"<<endl;
Console.WriteLine(endl<<"4:T-SHABUR"<<endl;
Console.WriteLine(endl<<"5:T-DABROTO"<<endl;
Console.WriteLine(endl<<"6:T-JAHID"<<endl;
Console.WriteLine(endl<<"7:T-ARIF"<<endl;
Console.WriteLine(endl<<"8:T-MORSHAD"<<endl;
Console.WriteLine(endl<<"9:T-AGIJ"<<endl;
Console.WriteLine(endl<<"10:T-SULTAN"<<endl;
Console.WriteLine(endl<<"11:T-LIAJE"<<endl;
Console.WriteLine(endl<<"12:T-MD.MOHAMOD"<<endl;
Console.WriteLine(endl<<"13:Quit";
Console.WriteLine(endl<<endl<<endl;
Console.WriteLine("IF YOU DO NOT WANT THIS SCHEDULE ENTER:12");
Console.WriteLine("/n,/n");
Console.WriteLine("Enter your choice::";
Console.WriteLine("/n,/n,/n"); //less then 12
do
{
y= Convert.ToInt32(Console.ReadKey());
if(y>12)
break;
Console.WriteLine("/n,/n,/n");
Console.WriteLine("time--- 8.00 8.50 9.40 10.40 11.30 12.20 2.30");
Console.WriteLine("/n,/n,/n");
switch(y)
{
case 1:
s.t_AJHER();
break;
case 2:
s.t_NAWAJ();
break;
case 3:
s.t_RAJIB();
break;
case 4:
s.t_SHABUR();
break;
case 5:
s.t_DABROTO();
break;
case 6:
s.t_JAHID();
break;
case 7:
s.t_ARIF();
break;
case 8:
s.t_MORSHAD();
break;
case 9:
s.t_AGIJ();
break;
case 10:
s.t_SULTAN();
break;
case 11:
s.t_LIAJE();
case 12:
s.t_MOHAMOD();
default:
break;
}
Console.WriteLine("/n,/n,/n");
}
while(x<=12);
Console.WriteLine("--------------------********END*********------------------");
Console.ReadKey();
return 0;
}
}
class day
{
public sun()
{
Console.WriteLine("sun cse eee L cse(A-group)";
Console.WriteLine("/n,/n");
Console.WriteLine(" RAJIB SHABUR AJHER & NAWAJ ");
return 0;
}
mon()
{
Console.WriteLine("mon mat cse che eee L me1270 ");
Console.WriteLine("/n,/n");
Console.WriteLine(" JAHID AJHER MORSHAD DABROTO LIAJE & SULTAN ");
return 0;
}
tue()
{
Console.WriteLine("tue mat che cse cse L cse(B-group)");
Console.WriteLine("/n,/n");
Console.WriteLine(" ARIF AGIJ NAZRUL NAWAJ AJHER & NAWAJ ");
return 0;
}
wed()
{
Console.WriteLine("wed -eeelab(A-group)----- cse eee Lab Hum ");
Console.WriteLine("/n,/n");
Console.WriteLine(" SHABUR RAJIB DABROTO MD.MOHAMOD ");
return 0;
}
thu()
{
Console.WriteLine("thu che cse mat ------che(lab)-------- Leeelab(B-group)");
Console.WriteLine("/n,/n");
Console.WriteLine(" MORSHAD RAJIB JAHID MORSHAD AJHER & NAWAJ ");
return 0;
}
}
//******************End of day class*********************//
//--------**********************---------//
class teacher
{
public t_AJHER()
{
Console.WriteLine("sun Lcse(A-group) ");
Console.WriteLine("/n,/n");
Console.WriteLine("mon cse ");
Console.WriteLine("/n,/n");
Console.WriteLine("tue Lcse(B-group) ");
Console.WriteLine("/n,/n");
return 0;
}
t_NAWAJ()
{
Console.WriteLine("sun Lcse(A_group) ");
Console.WriteLine("/n,/n");
Console.WriteLine("tue cse Lcse(B-group) ");
Console.WriteLine("/n,/n");
Console.WriteLine("thu cse ") ;
Console.WriteLine("/n,/n");
return 0;
}
t_RAJIB()
{
Console.WriteLine(" cse ");
Console.WriteLine("/n,/n");
Console.WriteLine("tue cse ");
Console.WriteLine("/n,/n");
Console.WriteLine("wed cse ");
Console.WriteLine("/n,/n");
return 0;
}
t_SHABUR()
{
Console.WriteLine("sun eee ");
Console.WriteLine("/n,/n");
Console.WriteLine("wed -eeelab(A-group)--- ");
Console.WriteLine("/n,/n");
Console.WriteLine(" Leeelab(B-group)");
Console.WriteLine("/n,/n");
return 0;
}
t_DABROTO()
{
Console.WriteLine("mon eee ");
Console.WriteLine("/n,/n");
Console.WriteLine("wed eee ");
Console.WriteLine("/n,/n");
return 0;
}
t_JAHID()
{
Console.WriteLine("mon mat ");
Console.WriteLine("/n,/n");
Console.WriteLine("thu mat ");
Console.WriteLine("/n,/n");
return 0;
}
t_ARIF()
{
Console.WriteLine("tue mat ");
Console.WriteLine(endl<<endl;
return 0;
}
t_MORSHAD()
{
Console.WriteLine("tue che ");
Console.WriteLine("/n,/n");
Console.WriteLine("thu che ------che(lab)---------- ");
Console.WriteLine("/n,/n");
return 0;
}
t_AGIJ()
{
Console.WriteLine("mon che ");
Console.WriteLine("/n,/n");
return 0;
}
t_LIAJE()
{
Console.WriteLine("mon L me1270-F,T ");
Console.WriteLine("/n,/n");
return 0;
}
t_SULTAN()
{
Console.WriteLine("mon L me1270-F,T ");
Console.WriteLine("/n,/n");
return 0;
}
t_MOHAMOD()
{
Console.WriteLine(" Lab Hum ");
return 0;
}
}
//********************************************************//
//END TEACHER CLASS//
//"*********************************************"//
}
解决方案
Rather than convert C++ code into C#[^], try to understand what it does. Then write it using C# and .NET objects, methods, etc.
Here is some useful information: C++ -> C#: What You Need to Know to Move from C++ to C#[^]
First obvious. Every method should have return type.
For example:
public sun()
should be declared:
public int sun()
It looks like your methods return always 0, but you are not using returned values in your code. So perhaps you should considere removing
return 0; lines and declare your methods like:
public void sun()
Now try to compile it and see what other errors you are getting.
这篇关于[不是问题] C#方法声明/创建的问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文