0
I would like a class that is not static to be available for the entire application. At first I thought about turning this class into static, but for obscure reasons that are beside the point, I can’t make it static.
So I researched something about and found some things, follow example:
Considering the classes
public class TesteInstancia
{
public decimal A { get; set; }
public string B { get; set; }
}
public static class TesteStatic
{
public static TesteInstancia testeInstancia;
}
From what I understand the class TesteStatic
will get the reference to the object TesteInstancia
.
How to pass the value instead of the reference?
There is how to do this in a "better way" ?
EDIT
Thank you all for the clarifications, I have reached a "solution". Creating a clone of the original class it can be changed that did not reflect in the clone, it solves for now my problem, I will post here.
public class TesteInstancia : ICloneable
{
public decimal A { get; set; }
public string B { get; set; }
public object Clone()
{
return this.MemberwiseClone();
}
}
public static class TesteStatic
{
public static TesteInstancia MyProperty { get; set; }
}
An available class or instance of that class?
– TotallyUncool
Could you explain further what you mean when you say "available for the entire application"? A public class is now available.
– Randrade
But this is a static class ;) The problem is this obscure motif, especially if you can’t use anything static, but the solution is to use something static :) The best way is to make a static class soon. You cannot store a value in something that is a reference. Perhaps a more concrete example will help demonstrate what you want.
– Maniero
@Totallyuncool, a class instance.
– Robss70
@bigown, it is precisely this obscure motive that disturbs.
– Robss70
I closed because with the edition the question became completely meaningless, if that’s what had been asked originally and answered was not what I really wanted to know. If you make the question clearer you can reopen it. The fact that you have an obscure reason also contributes.
– Maniero
Singleton is the answer to your problem
– TotallyUncool
@Totallyuncool according to his edition, no :)
– Maniero
@Bigown is, I was wrong by the way s
– TotallyUncool