1Basic input and output
Copy the codeThe code is as follows:
static void main(string[] args)
{
("Enter something");
string s=();
("Welcome"+s);
();
}
2. Use of structure types
Copy the codeThe code is as follows:
namespace
{
struct student
{
public string stu_id;
public string name;
public int age;
public int score;
}
class program
{
static void maini(string[] args)
{
student s;
s.stu_id='' 09306101'';
=''Xiaohong'';
=29;
=99;
(''Student number:''+s.stu_id);
();
}
}
}
3. Use of arrays, find the maximum and minimum value of the array
Copy the codeThe code is as follows:
static void mian(string[] args)
{
int max,min;
int[] a=new int[10]{1,24,3,72,37,45,41,5,44,8};
max=a[0];
min=a[0];
for(int i=1;i<;i++)
{
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
}
(''maximum value {0}'',max);
(''Min {0}'',miin);
();
}
}
}
4. Common methods of string
Copy the codeThe code is as follows:
static void main(string[] args)
{
("Please enter the user name:");
string s=();
if((s,''wxy'')==0)
{
('' The demonstration method is started: ");
string str='' hello'';
("Copy string: {0},(str1));
("String: {}",(3.2));
("Insert: {0}'',(3,"******"));
}
else
{
("User name is wrong, exit the program");
}
();
}}}
5. Explicit conversion and implicit conversion
Copy the codeThe code is as follows:
static void main(string[] args)
{
("Implicit conversion:");
short i=1234;
(i);
int s=i;
(s);
("Explanatory conversion:");
long l=12345;
(l);
int l1=(int)l;
(l1);
();
}
6. Packing and unboxing
Copy the codeThe code is as follows:
static void main(string[] args)
{
int i=123;
object obj=123;
int j=(int)obj;
("x={0}",i);
("obj={0}",obj);
("j={0}",j);
();
}