Home > Software engineering >  C # basic problems
C # basic problems

Time:11-20

1. The first code:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;

The namespace ConsoleApplication30
{
The class student
{
Int no;
String name;
Int deg1;
Int deg2;
Int deg3;
Static int sum1=0;
Static int sum2=0;
Static int sum3=0;
Static int sn=0;
Public student (int n, string na, int d1, int d2, int d3)
{no=n; Name=na. Deg1=d1; Deg2=d2; Deg3=d3; Sum1 +=deg1; Sum2 +=deg2; Sum3 +=deg3; Sn++; }
Public void disp () 1.//don't understand what meaning is not void return ,
{the Console. WriteLine (" student number: name: {0} {1} Chinese: mathematics: {2} {3} English: {4} P score: {5: f} ", no, name, deg1, deg2, deg3, (double) (deg1 + + deg3 deg2)/3); } 2.//add double here is to show conversion??
Public static double avg1 () {return (double) sum1/sn; }
Public static double avg2 () {return (double) sum2/sn; }
Public static double avg3 () {return (double) sum3/sn; }//what do you mean return: why do you want to add the return,
}
Class Program
{
The static void Main (string [] args)
{
Student s1=new student (1, "xyh", 67,89,90);
Student s2=new student (2, "myh", 34,55,66);
Student s3=new student (3, "HCV", 24,43,75);
Console. WriteLine (" dear user output: ");
s1.disp();
S2. Disp ();
S3. Disp ();
Console. WriteLine (" the language score: mathematical average: {0} {1} scored an average English: {2} ");
Student. Avg1 ();
Student. Avg2 ();
Student. Avg3 (); 3.//this output results show that for the language score: mathematical average: {0} {1} scored an average English: {2}
//(4) why non-static can use, so a static method can only Console. WriteLine (" the language score: mathematical average: {0} {1} scored an average English: {2} ", student. Avg1 (); Student. Avg2 (); Student. Avg3 ());

}
}
}
5.//when a line of code to add ";" When not points not clear!
The second code:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;

The namespace ConsoleApplication31
{
Public class tpoint3
{
Int x, y;
Public int px 6.//attribute px, py and field x, y, what's the difference?
{
The get {return x; }
The set {x=value; }/ 7)/get and set don't understand what you mean?
}
Public int py
{
The get {return y; }
The set {y=value; }
}
}
Class Program
{
The static void Main (string [] args)
{
Tpoint3 p=new tpoint3 (); today//at the front is not defined function public tpoint3 () {}, why can call here? The system will default to you write?
P.p x=3; P.p y=8;
Console. WriteLine (" point=& gt; ({0}, {1}) ", p.p x, p.p y); pet-name ruby//here "=& gt;" What do you mean, what is the role?
}
}
}
[color=# FF0000 attending]//could you tell me what package do you mean? And when it is necessary to encapsulate field, have what effect?
[/color]Problem may be more... , every brother please address ~ ~ is there anyone learning communication on this group of ah

CodePudding user response:

For bosses to solve some of the problems can be ~ ~ ~

CodePudding user response:

You need to read a book!
But some grammar is the latest c # syntax sugar such as
"Point=& gt; ({0}, {1}) "is the final result of" point=& gt; (3, 8) "so=& gt; Is=& gt; Direct output out similar "name: zhang SAN" colon calculate format!

CodePudding user response:

1) void indicates no return value, so direct return if there is a return value double int string long a lot

CodePudding user response:

(2)//plus double is to display conversion here?? Calculation is mandatory, because your definition is of type int, so there is division, not converted to a double will only int battles, such as int 5/2=2, double 5/2=2.5

CodePudding user response:

Language score: mathematical average: {0} {1} scored an average English: {2}, {Number} in the said, after the parameters of the position, the Console. WriteLine (" the language score: mathematical average: {0} {1} scored an average English: {2} ", student. Avg1 (); Student. Avg2 (); Student. Avg3 ()); This is right
  • Related