Knowledge points
- string.Split(char s), splits the string string by s of char type, and the return value is string[] type
- int.Parse(String s), converts String type s into int type
Note: Create an empty object and introduce the code into the empty object. Enter the number + space + number in the Input, click play, and then the debug information will be displayed on the console.
using UnityEngine;
using System;
public class APlusB : MonoBehaviour
{
public string s;
private void Start()
{
APlusBByUnity(s);
}
private void APlusBByUnity(string s)
{
string[] ss = s.Split(' ');
int DebugLog = int.Parse(ss[0]) + int.Parse(ss[1]);
Debug.Log(DebugLog);
}
//private static void Main()
private static void APlusBByMono()
// 暂只知道static表示静态,未深度了解
{
// 来源于洛谷网
string[] input = Console.ReadLine().Split(' ');
Console.WriteLine(int.Parse(input[0]) + int.Parse(input[1]));
}
}