Since the C# using statement is just a syntactic sugar for try/finally{dispose} why does it accept multiple objects ONLY IF THEY ARE OF THE SAME TYPE?
I don't get it since all they need to be is IDisposable. If all of them implement IDisposable it should be fine but it isn't.
Specifically I am used to writing
using (var cmd = new Sql...
I saw this C# using statement in a code example:
using StringFormat=System.Drawing.StringFormat;
What's that all about?
...
I'm trying to build some .ascx controls into a class library for plugins for a CMS I'm building.
My project type is a typical C# class libary with references added for system.web.mvc & friends.
My problem arises in trying to create a strongly-typed user control. My control looks like this:
<%@ Control Language="C#" Inherits="System.W...
Take a look...
http://search.mysql.com/search?site=refman-41&q=using&lr=lang_en
The official MySQL site doesn't explain the USING command.
Can you do that please?
...
Having this code:
using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create)))
{
//save something here
}
Do we need to close the BinaryWriter? If not, why?
...
The following code gives me a System.IO.IOException with the message 'The process cannot access the file'.
private void UnPackLegacyStats()
{
DirectoryInfo oDirectory;
XmlDocument oStatsXml;
//Get the directory
oDirectory = new DirectoryInfo(msLegacyStatZipsPath);
//Check if the directory exists
if (oDirectory.Exists)
{
...
If I have a namespace like:
namespace MyApp.Providers
{
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
}
Does this mean that if I create other files and classes with the same namespace, the using statements are shared, and I don't need to include them again?
...
Visual Studio will automatically create using statements for you whenever you create a new page or project. Some of these you will never use.
Visual Studio has the useful feature to "remove unused usings".
I wonder if there is any negative effect on program performance if the using statements which are never accessed, remain mentioned ...
Per my other question here about Disposable objects, should we call Close() before the end of a using block?
using (SqlConnection connection = new SqlConnection())
using (SqlCommand command = new SqlCommand())
{
command.CommandText = "INSERT INTO YourMom (Amount) VALUES (1)";
command.CommandType = System.Data.CommandType.Text;
...
In VB.Net you can do something like the following without any issues... just ignore the fact that this is a pretty useless class :-)
Imports System
Public Class Class1
Public Shared Function ArrayToList(ByVal _array() As String) As Collections.Generic.List(Of String)
Return New Collections.Generic.List(Of String)(_array)
...
Is it legal?
class SomeClass {
public:
static void f();
};
using SomeClass::f;
Edit: I forgot to qualify function. Sorry.
...
I am working on a project and have to compare two files and see if they match eachother excatly.
My first draft before alot of error checking and validation came up with:
DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory + "\\TestArea\\");
FileInfo[] files = di.GetFiles(filename + ".*");
FileInfo outputFile = fil...
I have some questions about the following code:
using System;
namespace ConsoleApplication2
{
public struct Disposable : IDisposable
{
public void Dispose() { }
}
class Program
{
static void Main(string[] args)
{
using (Test()) { }
}
static Disposable Test()
...
Hi,
Well Guess I could need some help here. I'm new to JOGL, and I am trying to draw on the 3d canvas perhaps just anything, but the point is to use mouse drag events. Any idea how am I be able to do that?
I try something as below but it did not worked out.
And also in the below codes, I do not understand why the display() method is b...
Potentially embarrassing question, but there is obviously something I'm missing that I want/need to know.
I expect the following code to create a new table row with new cells to be rendered later. And that's what it does ... as you would expect.
using (TableRow tr = new TableRow())
{
using (TableCell td = new TableCell())
{
...
The using(...) statement is syntactic sugar for try{} finally {}.
But if I then have a using statement like below:
using (FileStream fs = File.Open(path))
{
}
Now I want to catch the exceptions that opening this file could cause (and this is fairly high risk code in that it can fail due to the environment), but if I write try-catch...
If I create a new form called myForm, the top of myForm.h looks like this:
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections; //<<<< THIS ONE
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
None of these are even ...
Can someone please explain the below to me. First is how I call the method and the second bit is the LINQ Method.
My curiousity stems from the fact that I get a context error if I un-comment the using portion.
Why? I apparently do not fully understand using and context's. And I would like to better understand this.
Guid workerID =...
I'm currently writing a fairly complex paint method for a user control, involving a fair amount of drawing code. I know that all GDI+ resources need to be properly disposed so I wrap each of those in a using block.
But when I noticed that I used three using blocks for three different SolidBrushes I wondered whether I couldn't just re-us...
I've written my own custom data layer to persist to a specific file and I've abstracted it with a custom DataContext pattern.
This is all based on the .NET 2.0 Framework (given constraints for the target server), so even though some of it might look like LINQ-to-SQL, its not! I've just implemented a similar data pattern.
See example be...