out


out 키워드를 사용하면 변수를 전달하기전 초기화 하지 않고도 전달이 가능


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            int a;


            Add(out a);

            Console.WriteLine("a={0}", a);

        }


        static void Add(out int a)

        {

            a = 100;

        }

    }

}


결과:

a=100


'Programming > C#' 카테고리의 다른 글

params  (0) 2017.08.06
foreach  (0) 2017.08.06
변수 출력  (0) 2017.08.06
c# 동적으로 textbox 생성하기  (0) 2017.08.05
winform 파일 쓰기  (0) 2017.08.05

params

길이에 제한받지 않고 수를 넘겨주어 그 수의 총 합을 구하고 싶을때 사용

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("sum={0}", total(20, 10, 40, 4, 7, 6, 44, 55, 2));
            Console.WriteLine("sum={0}", total(30, 4, 5));
        }

        static int total(params int[] list)
        {
            int sum = 0;

            for (int i = 0; i < list.Length; i++)
                sum += list[i];

            return sum;
        }
    }
}


'Programming > C#' 카테고리의 다른 글

out  (0) 2017.08.06
foreach  (0) 2017.08.06
변수 출력  (0) 2017.08.06
c# 동적으로 textbox 생성하기  (0) 2017.08.05
winform 파일 쓰기  (0) 2017.08.05

foreach (변수 in 배열 or 컬렉션) {

// 실행될 코드

}




using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace Program1

{

    class Program

    {

        static void Main(string[] args)

        {

            int[] arr = { 1, 2, 3, 4, 5, 6, 7 };


            foreach (int i in arr)

                Console.WriteLine("i: {0}", i);

        }

    }

}


'Programming > C#' 카테고리의 다른 글

out  (0) 2017.08.06
params  (0) 2017.08.06
변수 출력  (0) 2017.08.06
c# 동적으로 textbox 생성하기  (0) 2017.08.05
winform 파일 쓰기  (0) 2017.08.05

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            object a = 12345678910;

            object b = 12345.67891011;

            object c = true;

            object d = "안녕하세요";

            

            Console.WriteLine("a={0}, b={1}, c={2}, d={3}", a, b, c, d);

        }

    }

}



'Programming > C#' 카테고리의 다른 글

params  (0) 2017.08.06
foreach  (0) 2017.08.06
c# 동적으로 textbox 생성하기  (0) 2017.08.05
winform 파일 쓰기  (0) 2017.08.05
openFileDialog를 이용하여 파일읽기  (0) 2017.08.05

private void button1_Click(object sender, EventArgs e)

{

       //seq달기

       TextBox t = new TextBox();

       t.Name = "textbox"+ seq;

       t.Location = new Point(100, 100 * seq);

       t.KeyDown += new KeyEventHandler(t_KeyDown);  //KeyDown 이벤트

       this.Controls.Add(t);

}


'Programming > C#' 카테고리의 다른 글

foreach  (0) 2017.08.06
변수 출력  (0) 2017.08.06
winform 파일 쓰기  (0) 2017.08.05
openFileDialog를 이용하여 파일읽기  (0) 2017.08.05
WinForm과 WPF  (0) 2017.07.02
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 System.IO;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
        }
  
 

        //파일쓰기

        private void FileWrite(string str)
        {
            FileStream fs = new FileStream(str, FileMode.Append, FileAccess.Write);
            //FileMode중 append는 이어쓰기. 파일이 없으면 만든다.

            StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
            sw.WriteLine(str);
            sw.Flush();
            sw.Close();
            fs.Close();


        }

        private void button1_Click(object sender, EventArgs e)
        {
            FileWriteLine(@"C:\test\tes1t.txt"); //혹은 FileWriteLine("C:\\test\\tes1t.txt");
            FileWriteLine("ㅋㅋㅋ만세!");
        }

    }
}

FileWriteLine(@"C:\tes1t.txt"); <-error 남, C:\에서의 파일 쓰기 권한이 없어서 생기는듯...



출처 : http://egloos.zum.com/rapidme/v/5998041

'Programming > C#' 카테고리의 다른 글

변수 출력  (0) 2017.08.06
c# 동적으로 textbox 생성하기  (0) 2017.08.05
openFileDialog를 이용하여 파일읽기  (0) 2017.08.05
WinForm과 WPF  (0) 2017.07.02
윈폼(WinForm 의 구성요소, 생성코드)  (0) 2017.07.02



using System;

using System.Windows.Forms;

 

namespace LogReader

{

    public partial class Main : Form

    {

 

        public Main()

        {

            InitializeComponent();    

        }

 

        private void tsm_Open_Click(object sender, EventArgs e)

        {

            ShowFileOpenDialog();

        }

 

        /// <summary>

        /// 그림파일오픈창을 로드후 해당 파일의 FullPath를 가져온다.

        /// </summary>

        /// <returns>파일의 FullPath 파일이 없거나 선택을 안할경우 ""를 리턴</returns>

        public string ShowFileOpenDialog()

        {

            //파일오픈창 생성 및 설정

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title = "파일 오픈 예제창";

            ofd.FileName = "test";

            ofd.Filter = "그림 파일 (*.jpg, *.gif, *.bmp) | *.jpg; *.gif; *.bmp; | 모든 파일 (*.*) | *.*";

            //필터설명|필터옵션|필터설명|필터옵션|......


            //파일 오픈창 로드

            DialogResult dr = ofd.ShowDialog();

             

            //OK버튼 클릭시

            if (dr == DialogResult.OK)

            {

                //File명과 확장자를 가지고 온다.

                string fileName = ofd.SafeFileName;

                //File경로와 File명을 모두 가지고 온다.

                string fileFullName = ofd.FileName;

                //File경로만 가지고 온다.

                string filePath = fileFullName.Replace(fileName, "");

 

                //출력 예제용 로직

                label1.Text = "File Name  : " + fileName;

                label2.Text = "Full Name  : " + fileFullName;

                label3.Text = "File Path  : " + filePath;

                //File경로 + 파일명 리턴

                return fileFullName;

            }

            //취소버튼 클릭시 또는 ESC키로 파일창을 종료 했을경우

            else if (dr == DialogResult.Cancel)

            {

                return "";

            }

 

            return "";

        }

 

         

    }

}





출처: http://mirwebma.tistory.com/121 [Run and Fly]

'Programming > C#' 카테고리의 다른 글

c# 동적으로 textbox 생성하기  (0) 2017.08.05
winform 파일 쓰기  (0) 2017.08.05
WinForm과 WPF  (0) 2017.07.02
윈폼(WinForm 의 구성요소, 생성코드)  (0) 2017.07.02
DLL 파일  (0) 2017.07.02
http://blog.naver.com/PostView.nhn?blogId=jjoommnn&logNo=130033346945&parentCategoryNo=&categoryNo=&viewDate=&isShowPopularPosts=false&from=postView

 

'Programming > C#' 카테고리의 다른 글

winform 파일 쓰기  (0) 2017.08.05
openFileDialog를 이용하여 파일읽기  (0) 2017.08.05
윈폼(WinForm 의 구성요소, 생성코드)  (0) 2017.07.02
DLL 파일  (0) 2017.07.02
.Net Framework란?  (0) 2017.07.02

+ Recent posts