Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create a object in C# without the use of new Keyword? [closed]
- Type type = typeof(MyClass);
- object[] parameters = new object[]{1, "hello", "world" };
- object obj = Activator.CreateInstance(type, parameters);
- MyClass myClass = obj as MyClass;
- static class Foo
- {
- public static void Bar()
- {
- Console.WriteLine("Foo.Bar()");
- }
- }
- static class PizzaFactory
- {
- static Pizza CreatePizza(String topping)
- {
- if (topping == "cheese")
- {
- return new CheesePizza();
- }
- else if (topping == "salami")
- {
- return new SalamiPizza();
- }
- }
- }
- class Pizza { }
- class CheesePizza : Pizza { }
- class SalamiPizza : Pizza { }
- var s = default(string); // null
- var i = default(int); // integer (0)
- typeof(MyType)
Add Comment
Please, Sign In to add comment