简体   繁体   中英

Combining two separate pieces of code to work together in C#

class Program
{
    static void Main(string[] args)
    {
        StrokeScribeClass ss = new StrokeScribeClass();

        ss.Alphabet = enumAlphabet.DATAMATRIX;
        ss.DataMatrixMinSize = 16;
        ss.ECI = 0;
        ss.UTF8 = false;

        Console.Write("Input : ");
        string txt;
        txt = Console.ReadLine();

        ss.Text = txt;
        int w = ss.BitmapW;
        int h = ss.BitmapH;
        ss.SavePicture(txt + ".bmp", enumFormats.BMP, w * 2, h * 2);
        System.Console.Write(ss.ErrorDescription);
    }
}

class WriteTextFile
{
    static void Second()
    {
        Console.Write("Input : ");
        string txt;
        txt = Console.ReadLine();

  System.IO.File.WriteAllText(@"C:\Users\Chad\Desktop\studio07\rinhoceros\20140428\WriteText.txt", txt);
    }
}

First class Program is the part where the console makes a datamatrix with the words typed in to the console and second class WriteTextFile part ; what I was trying to do is to make a txt file out of the text typed in to the console from first code (class program) they both work fine separately. I'm thinking having to class might be a problem and static void can be a problem. please help me out

Pass your Second class the data you wish to store in the text file:

class Program
{
    static void Main(string[] args)
    {
        StrokeScribeClass ss = new StrokeScribeClass();

        ss.Alphabet = enumAlphabet.DATAMATRIX;
        ss.DataMatrixMinSize = 16;
        ss.ECI = 0;
        ss.UTF8 = false;

        Console.Write("Input : ");
        string txt;
        txt = Console.ReadLine();

        ss.Text = txt;
        int w = ss.BitmapW;
        int h = ss.BitmapH;
        ss.SavePicture(txt + ".bmp", enumFormats.BMP, w * 2, h * 2);
        System.Console.Write(ss.ErrorDescription);

        WriteTextFile.Second(txt);
    }
}


class WriteTextFile
{
    static void Second(string fileText)
    {
        System.IO.File
          .WriteAllText(@"C:\Users\Chad\Desktop\studio07\rinhoceros\20140428\WriteText.txt", fileText);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM