'

alswlek의 이미지
mauri의 이미지

// 그리고 표시된 체크박스라면 args배열에 이름을 차례대로 저장을 한다.
string[] args = new string[arrayLength];
int argsIndex = 0;
 
for (int i = 0; i < cbs.Length; i++)
{
    if (cbs[i].Checked)
    {
        cbs[i].Enabled = false;
        args[argsIndex++] = cbs[i].Text;
    }
}

위 코드대로라면 이미 args에 체크된 체크박스의 이름이 들어간 상태입니다.
예로 1, 3번이 체크됐다면 1, 3번의 이름이 들어가겠지요?

근데 출력하는쪽에서

for (int i = 0; i < src; i++)
{
    if (cbs[i].Checked)
    {
        prime.WriteLine(args[i]);
    }
}

이런식으로 체크박스가 체크 되었는지를 또 다시 확인을 하고 있으니까요.
src는 2가 들어가 있을테니 체크박스 0, 1번이 체크되었나 확인하고, 체크 되있으면 출력하게 되겠지요?

이미 체크된 체크박스의 문자열만 들어가 있으므로 위 if (cbs[i].Checked)는 필요 없습니다.

내용추가....
가급적이면 코드를 적어드리지는 않는데요.
지금 보면 불필요한 코드가 너무 많아서 간단히 정리를 했으니까요.

한번 살펴보시고, 어떤것이 불필요했는지를 확인해 보시기 바랍니다.

System.Collections.ArrayList lstName = new System.Collections.ArrayList();
 
//모든 컨트롤 갯수 만큼 for문을 돌림, 체크박스 뿐아니라 버튼, 라벨까지 전부 포함
foreach (Control control in this.Controls)
{
    // 체크박스라면
    if (control is CheckBox)
    {
        // 체크되어 있다면
        if(((CheckBox)control).Checked)
        {
            control.Enabled = false;    // Disable상태로 바꾸고
            lstName.Add(control.Text);  // 텍스트를 저장
        }
    }
}
lstName.Sort(); // 텍스트를 정렬
 
// 파일이 없으면 만들고, 있으면 추가함
StreamWriter prime = new StreamWriter(REGISTER_FILE_NAME, true);
prime.WriteLine("--------------예약한 좌석 표시---------------");
 
// 체크된 이름을 파일에 출력
foreach (String name in lstName)
{
    prime.WriteLine(name);
}
prime.Close();

alswlek의 이미지

코딩이란 저에겐 아직까지 너무나 심오한듯 ...

감사합니다

mauri의 이미지

즐프되세요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.