2013-12-09 8 views
0

나쁜 영어로 죄송합니다.오류 : 암시 적으로 'string'유형을 'string []'으로 변환 할 수 없습니다.

내 Windows 양식의 값을 내가 작성한 클래스 정의로 전달할 때 문제가 있습니다.

내 Windows 정의에서 전달 된 값을 저장하기 위해 클래스 정의에 일곱 개의 배열을 선언했습니다. 내 문제는 내가 항상 내가 나에게 부여 된 다른 작업에 대한 아이디어를 얻기 위해 노력했다

Cannot implicitly convert type 'string' to 'string[]'

같은 오류를 얻고 있지만 여전히 내 작품에 오류를 던지고 것으로 보인다는 것이다. 여기

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace BankTransaction 
{ 

public class Transactions 
{ 
    String username, password; 
    decimal deposit, withdrawal, balance; 
    decimal percentInterest; 
    private decimal projectedInterest; 
    private String uname; 
    public string fName, lName, mInitial, pword, actType, uName; 
    const Int64 MAX_SIZE = Int64.MaxValue; 

    public static String[] firstName = new String [MAX_SIZE]; 
    public static String[] lastName = new String[MAX_SIZE]; 
    public static String[] mi = new String[MAX_SIZE]; 
    public static String[] pass = new String[MAX_SIZE]; 
    public static String[] userName = new String[MAX_SIZE]; 
    public static String[] accountType = new String[MAX_SIZE]; 
    public static decimal[] deposito = new decimal[MAX_SIZE]; 
    static int count = 0; 
    public static int that; 
    public static int number = 10001; 

    public void registerLoginDetails() 
    { 
     firstName[count] = fName; 
     lastName[count] = lName; 
     mi[count] = mInitial; 
     pass[count] = pword; 
     accountType[count] = actType; 
     userName[count] = uName; 
     deposito[count] = deposit; 
     count++; 
     number++; 
    } 

    public decimal computeProjectedInterest(decimal initialBalance, decimal numOfYears) 
    { 

     if (numOfYears < 1) 
     { 
      percentInterest = 0.00m; 
     } 

     if (numOfYears > 0 && numOfYears <= 3) 
     { 
      percentInterest = 0.02m; 
     } 

     if (numOfYears > 3 && numOfYears <= 5) 
     { 
      percentInterest = 0.05m; 
     } 

     if (numOfYears > 5 && numOfYears <=10) 
     { 
      percentInterest = 0.08m; 
     } 

     if (numOfYears > 10) 
     { 
      percentInterest = 0.12m; 
     } 

     projectedInterest = initialBalance * percentInterest * numOfYears; 
     return projectedInterest; 
    } 

    public decimal withdrawBalance() 
    { 
     return 0m; 
    } 

    public decimal depositBalance() 
    { 
     return 0m; 
    } 
} 
} 

그리고 상기의 WinForm 내 코드입니다 : 내 질문에 대답합니다 모든 사람에게 사전에

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using BankTransaction; 

namespace LabExam1 
{ 
public partial class Registration : Form 
{ 

    const long size = Int64.MaxValue; 
    public static Transactions trans = new Transactions(); 
    int i = 0; 

    public void confirmRegistration() 
    { 

     Transactions.firstName = txtFname.Text; 
     Transactions.lastName = txtLname.Text; 
     Transactions.mi = txtMi.Text; 
     Transactions.pass = txtPass.Text; 
     Transactions.deposito = nudDeposit.Value; 
     Transactions.accountType = cboType.Text; 
     Transactions.userName = ""; 
     trans.registerLoginDetails(); 
     i++; 


     this.Hide(); 
     Login lo = new Login(); 
     lo.ShowDialog(); 
    } 

    public Registration() 
    { 
     InitializeComponent(); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     cboType.SelectedIndex = 0; 
    } 

    private void btnRegister_Click(object sender, EventArgs e) 
    { 
     if (txtFname.Text == "" || txtLname.Text == "" || txtMi.Text == "" || txtPass.Text == "") 
     { 
      MessageBox.Show("Please fill up all required fields!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
     } 
     else 
     { 
      if (cboType.SelectedIndex == 0) 
      { 
       confirmRegistration(); 
      } 

      if (cboType.SelectedIndex == 1) 
      { 
       if (nudDeposit.Value < 2500.00m) 
       { 
        MessageBox.Show("The initial deposit for your account type is insufficient", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
       } 

       else 
       { 
        confirmRegistration(); 
       } 
      } 

      if (cboType.SelectedIndex == 2) 
      { 
       if (nudDeposit.Value < 3000.00m) 
       { 
        MessageBox.Show("The initial deposit for your account type is insufficient", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
       } 

       else 
       { 
        confirmRegistration(); 
       } 
      } 
     } 


    } 

    private void btnExit_Click(object sender, EventArgs e) 
    { 
     Application.Exit(); 
    } 

    private void btnGotoLogin_Click(object sender, EventArgs e) 
    { 
     this.Hide(); 
     Login lo = new Login(); 
     lo.ShowDialog(); 
    } 

} 

}

덕분에

여기 내 클래스 정의입니다.

+0

What line ????? –

+2

어떤 라인에서 예외가 발생합니까? –

+12

실제로 Int64.MaxValue의 7 개 배열입니까? 여기에 더 큰 문제가 있다고 생각합니다. – Steve

답변

2

static Transactions 개체 (끔찍한 디자인, BTW,하지만 아직 배우고 있다고 가정하지만 ...)의 공용 속성을 설정할 때 개별 값 속성 대신 공용 배열 속성을 설정하려고합니다.

Transactions.firstName = txtFname.Text; 
    Transactions.lastName = txtLname.Text; 
    Transactions.mi = txtMi.Text; 
    Transactions.pass = txtPass.Text; 
    Transactions.deposito = nudDeposit.Value; 
    Transactions.accountType = cboType.Text; 
    Transactions.userName = ""; 

있어야 컴파일러에게 오류를 해결하지만, 디자인을 문제를 해결하지 않는

Transactions.fName = txtFname.Text; 
    Transactions.lName = txtLname.Text; 
    Transactions.mInitial = txtMi.Text; 
    Transactions.pword = txtPass.Text; 
    Transactions.deposit = nudDeposit.Value; 
    Transactions.actType = cboType.Text; 
    Transactions.uName = ""; 

. 이것이 용서할 수있는 학습 프로젝트이지만 어떤 점에서 (아마도 codereview에) 다루어야 할 몇 가지 디자인 문제가 있습니다. 당신은 직접 문자열 변수로 문자열의 배열을 설정하는 코드

Transactions.firstName = txtFname.Text; 
Transactions.lastName = txtLname.Text; 
Transactions.mi = txtMi.Text; 
Transactions.pass = txtPass.Text; 
Transactions.deposito = nudDeposit.Value; 
Transactions.accountType = cboType.Text; 

에서

0

이봐, 인덱스를 사용해보십시오.

Transactions.firstName[index] = txtFname.Text; 
    Transactions.lastName[index] = txtLname.Text; 
... 
관련 문제