Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this questionThere is a public interface in the project with a value as follows:
Name3D MyName3D { get; set; }
Now in another location I am using a public sealed class, I added the namespace / using System.Interfacename. Now I want to set it like follows:
private readonly Interfacename m_MyName3D ;
private const string 3DName = ##;
How would i go aobut setting it up so ## is the value of MyName3D. Again I haven't done anything like this before. Just wanted to give it a try?
Would be really appreciated if I could get some detail onto how it works.
Update One
Do you mean this?
using Interfacename;
public sealed class InfoController : AsyncController
{
pr开发者_如何学Pythonivate readonly Interfacename m_MyName3D ;
private const string 3DName = ##;
You can not assign anything to a const member at runtime. You can however make 3DName a readonly property and relay the get accessor to the interface:
private string 3DName { get { return m_MyName3D.MyName3D; } }
But maybe I did not get what you are trying to do, if so please describe it more clearly.
edit: you are using two types for 3DName, Name3D and string. If Name3D has no conversion operators you need to use it throughout the property.
private Name3D 3DName { get { return m_MyName3D.MyName3D; } }
If you really need to return a string the you need to write a string conversion operator for Name3D:
struct/class Name3D
{
public static implicit operator string(Name3D name)
{
return name.whatever; // this needs to be the data holding member(s) of Name3D
}
}
精彩评论