코딩연습/프로그래머스 코딩테스트

[프로그래머스C#]leve1 문자열을 정수로 바꾸기

호아니 2020. 7. 13. 11:31

using System;
using System.Collections.Generic;
using System.Globalization;

public class Solution {
    public int solution(string s) {
        int answer = 0;

        if(s.Length>=1&&s.Length<=5)
        {
           char b= Convert.ToChar(s.Substring(0, 1));
               if(b=='-')
                {
                    answer = -Convert.ToInt32(s.Substring(1, s.Length-1));
                }else {answer=Convert.ToInt32(s.Substring(0, s.Length));}
        }
        return answer;
    }
}