以下为啥会报错呢?
Guid gg = (Guid)Session["LoginUserID"]; 这样写报错 :指定得转换无效
Guid gg = new Guid(Session["LoginUserID"]) 这样写报错:
错误 11 与“System.Guid.Guid(byte[])”最匹配的重载方法具有一些无效参数
除了下面这种写法,还有啥写法嘛?看着太不智慧了。
string gg = (string)Session["LoginUserID"];
Guid guid = new Guid(gg);
Overload List
Name Description
Guid(array<Byte>[]()[]) Initializes a new instance of the Guid class using the specified array of bytes.
Guid(String) Initializes a new instance of the Guid class using the value represented by the specified string. Guid(Int32, Int16, Int16, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte) Initializes a new instance of the Guid class using the specified integers and bytes.
Guid(UInt32, UInt16, UInt16, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte) Initializes a new instance of the Guid class using the specified unsigned integers and bytes.
Guid(Int32, Int16, Int16, array<Byte>[]()[]) Initializes a new instance of the Guid class using the specified integers and byte array. 而session中的类型是object,因为Guid的构造函数中并不包含只接受一个object参数的重载,因此会报错。
而
string gg = (string)Session["LoginUserID"];
Guid guid = new Guid(gg); 则使用了红色部分的构造函数。简单的写法是
Guid guid = new Guid(((string)Session["LoginUserID"]));
看看这个 弄明白构造函数吧
然后你想存就把guid存到Session里