[Mono-list] Questions about coding style
IBBoard
ibboard at gmail.com
Mon Aug 20 19:55:15 UTC 2012
Just in case no-one else spots it, you'll need a "static" keyword on
that GetConnection() declaration, otherwise you have to create an
instance to get a reference to the private static variable, which is
just odd :)
On 20/08/12 20:45, James Wright wrote:
>
> I'd create ConnectionFactory class, although feel free to ignore me,
> just thinking off the top of my head! :-)
>
> public class ConnectionFactory
> {
> private static MySqlConnection _connection;
> public MySqlConnection GetConnection()
> {
> if (_connection == null)
> {
> _connection = new MySqlConnection();
> }
> return _connection;
> }
> }
>
>
>
> On 20/08/2012 20:28, Philippe Grohrock wrote:
>> Thanks for the reply already and I'm sorry, I should've added the
>> lines of code.
>> static class GlobalVariables
>> {
>> public static MySqlConnection connection = new connection();
>> }
>> This way the whole program has access to it and can modify/query the
>> DB when needed (this is what I meant with global). At the moment I
>> have 2 of my windows using that connection, but there might be more in
>> the future. So is this a bad way of doing it? Would it be better to
>> have the connection be internal static? Should I declare it once after
>> the start of the program and then hand it over to the windows? I think
>> I also need to open a new topic about assemblies ;)
>> ------------------------------------------------------------------------
>> View this message in context: Re: Questions about coding style
>> <http://mono.1490590.n4.nabble.com/Questions-about-coding-style-tp4656301p4656321.html>
>> Sent from the Mono - General mailing list archive
>> <http://mono.1490590.n4.nabble.com/Mono-General-f1490591.html> at
>> Nabble.com.
>>
>>
>> _______________________________________________
>> Mono-list maillist -Mono-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-list
>
>
>
> _______________________________________________
> Mono-list maillist - Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
More information about the Mono-list
mailing list