将vb转换为c#代码

时间:2015-08-13 15:37:35

标签: c#

你能在这里帮助我吗,这是我朋友的工作(实际上我不知道他在哪里获得这段代码,它使用vb语言)并且我试图将代码转换为C#。认为这很容易,即使我缺乏c#知识,而且我从这里堆积起来。我从网上找到了一个vb.net到c#转换器,这就是结果: *见下面的评论

clsProcess.cs:

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;

[Serializable()]
public class clsProcess : IComparable<clsProcess>
{

    public int Priority
    {
        get { return _Priority; }
        set { _Priority = value; }
    }
    public Color ProcessColor
    {
        get { return _ProcessColor; }
        set { _ProcessColor = value; }
    }
    public double ArrTime
    {
        get { return _ArrTime; }
        set { _ArrTime = value; }
    }
    public double ExeTime
    {
        get { return _ExeTime; }
        set { _ExeTime = value; }
    }
    public string Label
    {
        get { return _Label; }
        set { _Label = value; }
    }

    public clsProcess()
    {
    }

    public clsProcess(int prior, double arr, double exe, string lbl, Color clr)
    {
        _Priority = prior;
        _ArrTime = arr;
        _ExeTime = exe;
        _Label = lbl;
        _ProcessColor = clr;
    }

    private double _ArrTime;
    private double _ExeTime;
    private string _Label;
    private int _Priority;

    private Color _ProcessColor;

    public int CompareTo(clsProcess other)
    {
        switch ((modGlobals.SortColumn))
        { 

//The method SortType from modGlobals.cs is the error.
//Error says: The name 'SortType' does not exist in the current context
//I'm getting error from here:
            case SortType.Arr:
                return this.ArrTime.CompareTo(other.ArrTime);
            case SortType.Exe:
                return this.ExeTime.CompareTo(other.ExeTime);
            case SortType.Label:
                return this.Label.CompareTo(other.Label);
            case SortType.Prior:
                return this.Priority.CompareTo(other.Priority);
//Until here.
        }
    }

}

modGlobals.cs:

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
static class modGlobals
{

    public enum SortType  //The error referring to.
    {
        Arr,
        Exe,
        Prior,
        Label
    }

    public static SortType SortColumn; //I doubt it has something to do here.


    public static List<clsProcess> CreateMemberwiseClone(List<clsProcess> pList)
    {

        List<clsProcess> tempList = new List<clsProcess>();
        int i = 0;
        for (i = 0; i <= pList.Count - 1; i++) {
            tempList.Add(CloneProcess(pList[i]));
        }
        return tempList;

    }

    public static clsProcess CloneProcess(clsProcess process)
    {

        clsProcess temp = new clsProcess();
        temp.ExeTime = process.ExeTime;
        temp.ArrTime = process.ArrTime;
        temp.Label = process.Label;
        temp.Priority = process.Priority;
        temp.ProcessColor = process.ProcessColor;
        return temp;

    }


    public static void MergeBlocks(ref List<clsBlock> blocks)
    {
        if (blocks.Count < 2)
            return;

        int i = 0;


        while (i < blocks.Count - 1) {

            if (blocks[i].BlockCaption == blocks[i + 1].BlockCaption) {
                blocks[i].BlockLength += blocks[i + 1].BlockLength;

                blocks.RemoveAt(i + 1);

                i -= 1;

            }

            i += 1;

        }

    }

}

你能在这里给我一个替代解决方案吗?

2 个答案:

答案 0 :(得分:0)

 public int CompareTo(clsProcess other)
{
 switch ((modGlobals.SortColumn))
    { 
        case modGlobals.SortType.Arr:
            return this.ArrTime.CompareTo(other.ArrTime);
        case modGlobals.SortType.Exe:
            return this.ExeTime.CompareTo(other.ExeTime);
        case modGlobals.SortType.Label:
            return this.Label.CompareTo(other.Label);
        case modGlobals.SortType.Prior:
            return this.Priority.CompareTo(other.Priority);
    }
    //This next part will happen if the switch statement doesnt find a match
    //use this to return some default value or a value that tells you it didnt find something
    //I'll use 0 as an example

    return 0;
    //now all paths return a value, even if it doesnt find a match in the switch statement
}

答案 1 :(得分:0)

您的静态类modGlobals应该只有静态成员。 SortType应该是静态的。

  public static enum SortType 
  {
        Arr,
        Exe,
        Prior,
        Label
  }