Skip to main content
some change in view to be more readable
Link
Rens Verhage
  • 5.9k
  • 5
  • 37
  • 53

What is the correct way to call a method from otheranother class?

The using statement or a static What is correct way to call method from other class?

Source Link
Jones
  • 13
  • 3

The using statement or a static method?

public partial class Form1 : Form { private void StartApp() { LobGamma.LogInPanel.FillComboBox(LogInpanel_ComboBox, LobGamma.Connection.ObtainConnection()); } } public class LogInPanel { public static void FillComboBox(ComboBox Box, SqlConnection con) { Box.Items.Clear(); using (con) { SqlCommand com = new SqlCommand("Select Id From UsersTable", con); con.Open(); using (SqlDataReader reader = com.ExecuteReader()) { while (reader.Read()) { Box.Items.Add(reader["Id"].ToString()); } reader.Close(); } } con.Close(); } 

I want to know if I am going the right way about using a method from another class. I only need to use the method once. Is the way I have done it by using a static method acceptable? or should the method be non-static.

If the method should be non-static, Is it best to Inherit from IDisposable so that I can use the Class in a Using Statement? or would simply creating an instance of the class and waiting for GC be acceptable?