Quantcast
Channel: C++博客-所有随笔
Viewing all articles
Browse latest Browse all 7882

C# 学习

$
0
0
//test.cs
using System;
class Student: IComparable
{
string name;
int Grade;
bool Listen;
public Student(string n)
{
name = n;
Grade = 0;
Listen = false;
}
public void print()
{
Console.WriteLine(name);
}
public string getname()
{
return name;
}
#region 
public int CompareTo(Student b)
{
return this.name.CompareTo(b.getname());
}
#endregion
static void Main(string[] args)
{
}
}
//prog.cs
class Program
{
static void Main(string[] args)
{
Student a = new Student ("aa");
Student b = new Student ("bb");
Swap(ref a, ref b);
a.print();
b.print();
}
static void Swap(ref Student a , ref Student b)
{
Student tem = a;
a = b;
b = tem;
Student[] stu = new Student[5];
stu[0] = new Student("bb");
stu[1] = new Student("aa");
stu[2] = new Student("dd");
      stu[3] = new Student("cc");
stu[4] = new Student("ee");
foreach(Student s in stu)
s.print();
var stu2 = stu.Orderby(o=>o.name);
foreach(Student s in stu2)
s.print();
}
}
//public class Cmp : IComparer<Student>
//{
// int IComparer<Student>.Compare(Student a, Student b)
// {
// return a.getname()< b.getname();
// }
//}

#include<iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<sstream>
#include
<string>
#include
<sys/types.h>
#include
<sys/wait.h>
                                                
using namespace std;

const int MAXN = 1000;
char hostname[MAXN];
char pathname[MAXN];
string cmline;
string cm1;
string cm2;
int main()
{
    cout
<<"------------------strat of SHELL program---------------------"<<endl;
    

    
while(true)    
    
{
        istringstream scin(cmline);
        gethostname(hostname,MAXN);
        getcwd(pathname,MAXN);
        printf(
"%s %s $ ",hostname,pathname);
        
int status;
        getline(cin,cmline);
        scin
>>cm1;
        getline(scin,cm2);
        cout
<<cmline<<endl;
        cout
<<cm1<<endl;
        cout
<<cm2<<endl;
        
if(cm1=="cd")
        
{
            system(cmline.c_str());
            cout
<<cmline<<endl;
            
continue;
        }

        
if(fork()!=0)
        
{
            waitpid(
-1,&status,0);    
        }

        
else
        
{

    
//        cout<<cm1<<endl;
    
//        cout<<cm2<<endl;
    
//        system("ls -l");
            system((cmline).c_str());
        }

    }


    cout
<<"-------------------end of SHELL program----------------------"<<endl;
    
return 0;

}




 



abilitytao 2014-09-02 23:27 发表评论

Viewing all articles
Browse latest Browse all 7882

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>