位置:首页 > 编程专栏 > C#

C# 根据对象输出字符串

C# 根据对象输出字符串
using System;

namespace ConsoleApp23
{
    class Program
    {
        static void Main(string[] args)
        {
            Guid id = Guid.NewGuid();
            Console.WriteLine(ObjectToString(id));
            Console.Read();
        }

        /// <summary>
        /// 根据对象输出字符串
        /// </summary>
        /// <param name="obj">传入obj</param>
        /// <returns></returns>
        public static string ObjectToString(object obj)
        {
            return obj != null ? obj.ToString() : null;
        }
    }
}

C# 社区推荐