字符串有什么东西吗?

时间:2016-06-04 07:50:50

标签: c# string

所以我试图从记事本中获取用户名,然后尝试登录lib。但它出现错误说它不存在...... {对不起英语}

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Skype4Sharp;
using Skype4Sharp.Events;
using Skype4Sharp.Auth;
using Skype4Sharp.Helpers;
using Skype4Sharp.Enums;
using System.Threading;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

namespace Contactbombtest {
  class Program {
    static Skype4Sharp.Skype4Sharp mainSkype;
    static SkypeCredentials authCreds;
    private SkypeCredentials skypeCredentials;

    public Program(SkypeCredentials skypeCredentials) {
      this.skypeCredentials = skypeCredentials;
    }

    static void Main(string[] args) {
      Console.WriteLine("Please provide the username.");
      string username = Console.ReadLine();
      Console.WriteLine("Sending contacts to " + username);
      foreach(string line in File.ReadLines(@"C:\Users\Mikael2\Desktop\skypebomb\file.txt", Encoding.UTF8)) {

        string[] text2 = line.Split(':');
        string getusername = text2[0];
        string getpassword = text2[1];
        Console.WriteLine("[LOG]: Sending request from account:  {0}:{1}", getusername, string.Join("", Enumerable.Repeat("*", getpassword.Length)));
        mainSkype.Login();
      }
      new Program(new SkypeCredentials(getusername, getpassword));
      while (true) {}
    }

  }
}

我总是得到这个错误,但我一直在尝试和尝试.. 你能帮帮我吗?

错误讯息: 错误CS0103名称' getpassword'在当前上下文中不存在 错误CS0103名称' getusername'在当前上下文中不存在

1 个答案:

答案 0 :(得分:2)

看起来你正在为每个循环声明你的变量。这意味着当循环完成时,变量不再在范围内。因此,当您尝试新的程序时,它们就不存在了。

尝试将字符串声明移到foreach循环之外。

string getpassword = string.Empty;
string getusername = string.Empty;
string[] text2;

foreach (string line in File.ReadLines(@"C:\Users\Mikael2\Desktop\skypebomb\file.txt", Encoding.UTF8))
{
    text2 = line.Split(':');
    getusername = text2[0];
    getpassword = text2[1];
    Console.WriteLine("[LOG]: Sending request from account:  {0}:{1}", getusername, string.Join("", Enumerable.Repeat("*", getpassword.Length)));
    mainSkype.Login();
}
new Program(new SkypeCredentials(getusername, getpassword));