Question List all math function (include in math class) in a listbox or combobox

pooya1072

Well-known member
Joined
Jul 5, 2012
Messages
84
Programming Experience
Beginner
hi
how can i list all math functions that are collected in math class into a listbox or combobox?
 
You can open the MSDN Library, navigate to the topic for the Math class, read the list of methods and copy the names of those you want to include into your ListBox. You seem to think that using code to dynamically read something from the Math class in order to populate the ListBox is required. It's not. The Math class is not going to change between one time someone runs your app and the next. It's not going to be different between one system and another. There's no downside to hard-coding the list of methods.
 
You could do this using the Reflections namespace i.e.

'Showing Overloads
Dim t As Type = GetType(Math)


Dim Meths() As MethodInfo = t.GetMethods


For Each s In Meths
ListBox1.Items.Add(s.Name + "(" + s.ReturnType.ToString + ")")
Next

Or

'No Overloads
Dim t As Type = GetType(Math)


Dim Meths() As MethodInfo = t.GetMethods


For Each s In Meths
If ListBox1.Items.Contains(s.Name) = False Then 'Do not show overloads
ListBox1.Items.Add(s.Name)
End If
Next

Both require: Imports System.Reflection
 
You can open the MSDN Library, navigate to the topic for the Math class, read the list of methods and copy the names of those you want to include into your ListBox. You seem to think that using code to dynamically read something from the Math class in order to populate the ListBox is required. It's not. The Math class is not going to change between one time someone runs your app and the next. It's not going to be different between one system and another. There's no downside to hard-coding the list of methods.

Well the time it would take to copy all the functions, compared to the 2-3 lines of code it takes to extract them through reflection, I guess is a downside.
 
Back
Top