How to call a non-static method in different assembly using Reflection in C# and VB.NET

To call a static method in different assembly using Reflection in C# and VB.NET you can use the snippet below.

Sample C#

Assembly assembly = Assembly.LoadFile(@"Assembly_Location");   
var type = assembly.Types().FirstOrDefault(x => x.FullName.Contains("MyClassName"));
var constructor = type.GetConstructor(Type.EmptyTypes);

var classObject = constructor.Invoke(new object[] { }); //call parameterless constructor
var classObject = constructor.Invoke(new object[] { param1 }); //call non-parameterless constructor

MethodInfo methodInfo = type.GetMethod("MyMethodName");
methodInfo.Invoke(classObject, new object[] { }); //pass classobject, parameterless method
methodInfo.Invoke(classObject, new object[] { param1 }); //pass classobject, parameterized method

Sample VB.NET

Dim assembly__1 As Assembly = Assembly.LoadFile("Assembly_Location")
Dim type__2 = assembly__1.Types().FirstOrDefault(Function(x) x.FullName.Contains("MyClassName"))
Dim constructor = type__2.GetConstructor(Type.EmptyTypes)

Dim classObject = constructor.Invoke(New Object() {})'call parameterless constructor
Dim classObject = constructor.Invoke(New Object() {param1})'call non-parameterless constructor

Dim methodInfo As MethodInfo = type__2.GetMethod("MyMethodName")
methodInfo.Invoke(classObject, New Object() {})'pass classobject, parameterless method
methodInfo.Invoke(classObject, New Object() {param1})'pass classobject, parameterized method

How to call a static method in different assembly using Reflection in C# and VB.NET

To call a static method in different assembly using Reflection in C# and VB.NET you can use the snippet below.

Sample C#

Assembly assembly = Assembly.LoadFile(@"Assembly_Location"); 
var t = assembly.Types().FirstOrDefault(x=>x.FullName.Contains("MyClassName"));
var method = t.GetMethod("MyMethodName", BindingFlags.Public | BindingFlags.Static);
method.Invoke(null, null); //assuming that the method does not have parameters
method.Invoke(null, new object[] { param1}); //assuming that the method has 1 parameter

Sample VB.NET

Dim assembly__1 As Assembly = Assembly.LoadFile("Assembly_Location")
Dim t = assembly.Types().FirstOrDefault(Function(x) x.FullName.Contains("MyClassName"))
Dim method = t.GetMethod("MyMethodName", BindingFlags.[Public] Or BindingFlags.[Static])
method.Invoke(Nothing, Nothing) 'assuming that the method does not have parameters
method.Invoke(Nothing, New Object() {param1}) 'assuming that the method has 1 parameter

How to count the different words of a string in Python

To count the different words of a string in Python you can use the following snippet.

Sample Python

    
input = "Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C. The language provides constructs intended to enable clear programs on both a small and large scale.Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library.Like other dynamic languages, Python is often used as a scripting language, but is also used in a wide range of non-scripting contexts. Using third-party tools, such as Py2exe or Pyinstaller, Python code can be packaged into standalone executable programs. Python interpreters are available for many operating systems.CPython, the reference implementation of Python, is free and open source software and has a community-based development model, as do nearly all of its alternative implementations. CPython is managed by the non-profit Python Software Foundation."
words = input.split(' ')

wordcounter = {}
for word in words:
    if word in wordcounter:
        wordcounter[word] += 1
    else:
        wordcounter[word] = 1

sortedWords = sorted([(counter,word) for word,counter in wordcounter.items()],reverse=True)
print "Word counts: " + str(sortedWords)
print "Most popular word: " + str(sortedWords[0][1]) + " used " + str(sortedWords[0][0]) + " times."