Note that there are some explanatory texts on larger screens.

plurals
  1. POC# referencing another .cs (method to split up code either in either procedural/oo way)
    text
    copied!<p>I come from a procedural world so bear with me on this. I am not sure of the "proper" terminology. I get functions - classes not so much (I gather they are blue prints but I can't convince myself to use them yet, probably because I do not understand how helpful they can be)</p> <p>I am attempting to create a C# console application (in VS2010). It acts in a procedural nature (starts from top, may reference a function every once in a while or try catch and then exits). My issue is that there will be say 4 pieces to the application - the portion that defines what the sql strings are, the portion that connects to the database, the portion that executes sql statements and the portion that does extra calculations based on the results.</p> <p>I'm trying to determine a way of splitting up these chunks of code into different files that I can call from - essentially keeping the default "program.cs" from being too bulky. My code up to date works its just a beating to scroll through to pick out items.</p> <p>Suggestions?</p> <p>(I understand this is very subjective)</p> <p>[addition]</p> <p>The structure of my code right now looks similar to the following - note, [[[[[ ]]]]] are what I refer to as chunks:</p> <pre><code> [[[[[ string sqlQueryFetchCalls = "sql lives here"; ... and more strings for sql... and more... and more ]]]]] SqlConnection mssqlConnection = new SqlConnection(params); try{ mssqlConnection.Open(); System.Console.WriteLine("connection opened");} catch (Exception errorVar){ output.Text = errorVar.ToString();} [[[[[ SqlDataReader results = null; SqlCommand exec_sqlQueryFetchCalls = new SqlCommand(sqlQueryFetchCalls, mssqlConnection); results = exec_sqlQueryFetchCalls.ExecuteReader(); while (results.Read()) { // do something }results.Close(); ... again... again ... again... again, though the resulting actions are quite different each time ]]]]] mssqlConnection.Close(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload