|
I guess that makes three of us.
|
|
|
|
|
I like "var", but you have to know where to use it... Used properly, it makes the code nicer to read... Used improperly, you're hammering nails into the heads of whoever has to maintain your code later on.
Good:
// You know exactly what type customerMap is, because it's right there.
var customerMap = new Dictionary<string, List<CustomerBusinessObject>>();
Bad:
// You have to dig into another function to figure out what type it is
var customerMap = mapGenerator.GetCustomerMap();
(Yes, it's a bad example, because Dictionary<string, ...>> should be defined as a class for readability, but you get the point)
|
|
|
|
|
No, it is only to be used when you can't know the type; it's not to be used simply as a crutch for lazy programmers.
|
|
|
|
|
Laziness has nothing to do with it. I know it was originally designed for linq queries (For which I usually do a ToArray() and strongly type it), but it can also make more readable code by getting rid of some of the redundancy.
Sure, I could type a long type definition twice, or copy-paste it, but it looks a lot cleaner if you only specify the type once.
|
|
|
|
|
Even though you may not be lazy, many are.
|
|
|
|
|
PIEBALDconsult wrote: it is only to be used when you can't know the type;
Not trying to start an argument here, just curious. Would you say all dynamic languages are hard to read and are only for lazy programmers?
Python, which many people proclaim as the language easiest to read and understand, doesn't let you specify types for variables. There is no keyword equivalent to var even.
Also, I'd think var is useful when you don't care about the actual type, only that it has certain methods or properties.
var result = CalculateSomething();
result.DoX();
The code expresses the intent that it doesn't care what type result is, as long as there is a DoX method on it (without which it won't compile, of course). In a way, it's almost like result is a generic or template parameter.
What do you think?
|
|
|
|
|
I don't know Python, and I guess I don't want to.
C# 4.0 has dynamic, but I've only seen a small demo of it, so I really can't say. I expect it will be abused as well.
|
|
|
|
|
Luc Pattyn wrote: Right. I haven't used var
Me too. But, I use the auto (equivalent for var introduced in C++0x) keyword extensively in C++ and it makes the code more readable.
|
|
|
|
|
Hi all,
Please help me with your ideas
From c#.net application how to perform scan operation using twain protocol?
thanks
|
|
|
|
|
The first result[^] of a google search[^], finds one on this very site. I'm sure many of the other 257000 results may prove fruitful too.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
this C header[^] file may prove useful.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
My C# compiler most strongly objects
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I know the feeling - I've still got a little more work to do on my MIDI wrapper, and most of the implementation has come from studying the relevant C header file rather than relying on stuff on PInvoke.net (which can be useful, but occaisionally just plain wrong) etc. It made my brain hurt - lots, which is why it's not finished yet!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi,
i can read a excel File but i can´t populate it on a datagrid. Can somebody help me?
That´s my code:
private void button1_Click(object sender, EventArgs e)
{
this.openFileDialog1.FileName = "*.xls";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
ApplicationClass xlApplication = new ApplicationClass();
Workbook xlWorkbook = null;
Worksheet xlWorksheet = null;
Range xlRange = null;
xlApplication.Visible = false;
xlApplication.ScreenUpdating = false;
xlApplication.DisplayAlerts = false;
string workbook = this.openFileDialog1.FileName;
xlWorkbook = xlApplication.Workbooks.Open(openFileDialog1.FileName, 0, true, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 0, false);
xlWorksheet = (Worksheet)xlWorkbook.Worksheets[1];
}
}
Now, how can i report this excel in my datagrid?
Thanks
|
|
|
|
|
Well you are on the right track.
What you have to do now is loop through the worksheet and populate a DataTable.
This can be a real pain in the ass if you don't know the "Schema" of the Worksheet.
If you know the last cell and column that data is in you can just loop through it and add new rows to the DataTable. If you don't know the last cell and column, this is where it's a pain in the ass, you have to look for them.
Once you have the data in a DataTable, just set the DataSource of your grid to the DataTable.
You can find a little bit more info on how to properly read excel here[^].
JUST REMEMBER when working with excel you actually have to loop through each open workbook / sheet and close them, pass the parameters for saving, to actually kill excel otherwise it just sits in the background taking up precious resources.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
You can also use SpecialCells[Excel.XlCellType.xlCellTypeLastCell] to get the last cell.
This returns a crll which will have the last row and last column.
I beleive it just finds the last one with data.
I believe it is a member of the worksheet class.
|
|
|
|
|
Hey thats great news .... where were you a few years back when I really needed that.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Hi all,
I am getting the error after performing LPR on 10 jobs
"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"
please help me...
|
|
|
|
|
Hi,
i am developing an application in Visual Studio 2008.
My Destination Framework - Setting is set to ".Net Framework 2.0"; I do not need special functions of .Net 3.5 and I want the tool installed as quick and easy as possible.
I am using the Built-In "Setup Project" to install my application.
The problem now is that When only including .Net Framework 2.0 in my installation package, the installer says it need .Net Framework 3.5. How can this happen?
If not really needed I want to keep using the 'old' Framwork 2.0.
Regards,
Chris
|
|
|
|
|
Check your project properties. What does the Application ->Target Framework say?
If that still says .NET Framework 3.5, then you know why its not using 2.0
|
|
|
|
|
This is the strange thing! I selected .Net Framework 2.0. But even in the begining when creating the setup Project it wants to include .Net Framework 3.5. I deselected 3.5 and selected 2.0.
On another machine where i tried the setup process, a message told me that 3.5 is needed and can be downloaded online.
|
|
|
|
|
Right click the setup solution on the solution explorer. At the bottom there is a "prerequisite" button. Make sure that the 3.5 Framework and 3.5 Framework SP1 are deselected. Maybe that will fix it.
|
|
|
|
|
This is where i delesected .NetFramwork 3.5 and only selected .NetFramwork 2.0.
|
|
|
|
|
Are you using any features that are only available in 3.5? LINQ for instance
|
|
|
|
|
Not to my knowledge. I am not using LINQ.
Is there a possibility to check what framework is needed; and because of what?
I thought Visual Studio would tell me when it needs 3.5 to compile...
|
|
|
|