Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Invoquer un membre avec ‘Activator’: Exemple de la classe ‘StringBuilder’

Charger,une,Assemblée,avec,un,nom
{filelink=17561}

using System;
using System.Reflection;
using System.Text;
 
public class Example
{
   public static void Main()
   {
      Type sbType = typeof(StringBuilder);
      object o = Activator.CreateInstance(sbType);
 
      sbType.InvokeMember("Append", BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod,
         Type.DefaultBinder, o, new object[] {"Salut, là bas."});
      Console.WriteLine(o.ToString());
 
      o = Activator.CreateInstance(sbType, new object[]{"Salut"});
 
      sbType.InvokeMember("Append", BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, Type.DefaultBinder, o, new object[] {" Bonjour"});
      Console.WriteLine(o.ToString());
   }
}

No comments yet.

Leave a Comment