Storing C# data structure into a SQL database

前端 未结 7 2050
半阙折子戏
半阙折子戏 2021-02-01 10:02

I am new to the world of ASP.NET and SQL server, so please pardon my ignorance ...

If I have a data structure in C# (for e.g. let\'s just say, a vector that stores some

7条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 10:20

    [Serializable]
    public struct Vector3
    {
        public double x, y, z;
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            Vector3 vector = new Vector3();
            vector.x = 1;
            vector.y = 2;
            vector.z = 3;
    
            MemoryStream memoryStream = new MemoryStream();
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            binaryFormatter.Serialize(memoryStream, vector);
            string str = System.Convert.ToBase64String(memoryStream.ToArray());
    
            //Store str into the database
        }
    }
    

提交回复
热议问题