|
publc class Thing
{
Thing () {}
public List<Foo> MyFoos {get; set;}
}
<pre>
How do you get the list to be defaulted to an empty list rather than null? Do I need to implement a private backing variable?
|
|
|
|
|
Either use a backing field and lazy initialization
public class Thing
{
private List<Foo> m_List;
Thing() { }
public List<Foo> MyFoos
{
get
{
if(m_List == null)
m_List = new List<Foo>();
return m_List;
}
set{ m_List = value; }
}
or use the constructor
public class Thing
{
Thing()
{
MyFoos = new List<Foo>();
}
public List<Foo> MyFoos {get; set;}
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Excellent answer... (Because I do it this way, of course.)
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Do you have to do it in every constructor? I put it in the default constructor but it doesn't seem to work when I instatiate using a different constructor.
|
|
|
|
|
You need to append :basename() to the constructor definitions.
public class MySuperAwesomeClass
{
public int AwesomeOne { get; set; }
public int NotAsAwesome { get; set; }
public string UselessCrap { get; set; }
public MySuperAwesomeClass()
{
AwesomeOne = 42;
NotAsAwesome = -1;
}
public MySuperAwesomeClass( string someValue ) : base()
{
UselessCrap = someValue;
}
}
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Appending :base() doesn't run the default constructor for that class. The debugger never enters the default constructor and all my list properties are still null if I instantiate using a different constructor.
|
|
|
|
|
Rather than append :base() , you should use :this() to call the default constructor in the current class. The use of base implies a call to a base class, whereas this refers to the current class.
|
|
|
|
|
Not quite. I suspect you're thinking of :this() instead.
|
|
|
|
|
Or initialize it in the constructor
--edit
What Mark said!
I are Troll
|
|
|
|
|
I want to ask if you used a wizard control on windows form? which one your recommend?
|
|
|
|
|
I always make my own using panels and a little bit of logic - not very difficult and much simpler than trying to manipulate some pre-existing control to fit my needs.
|
|
|
|
|
Thanks I did the same and it's fine now
|
|
|
|
|
I am currenctly using the AdRotator control on C# WinForm with AdvertismentFile but I want to make a use of mySQL and use it as source for my banner by selecting random banner from the database..
my question how can i set and use the Impressions?
|
|
|
|
|
Hello friends,
I need to create a application which sholud pop up near system tray(like skype or g-talk etc), can any one help me how to do this or any links or samples, I googled enough for the day, let me know any thing with u also guys?.
Thanks in Advance
|
|
|
|
|
|
So you googled enough! Instead of typing this long long question you should have googled this:
".NET" +"C#" +"system tray" +"pop up"
And Oh noze, even here on CP:
http://www.codeproject.com/miscctrl/balloonhelp.asp
Yes I see that was clearly asking to much of you.
*Sadly shakes head*
|
|
|
|
|
Dear,
I would like to please you if someone can help me with using .m files in C#. I have made some function in Matlab and now I need to use it in C# application. I made .dll file with matlab deploy tool but I have problem when I use it in C#, my programs dosn`t execute, when I run it?
Thanks
|
|
|
|
|
|
anyone know of a way of subtract image from image to get the difference?
|
|
|
|
|
This really depends on what you mean by difference (i.e. subtraction).
You could iterate over the points and subtract the
RGB values from each other to gain your new image.
Leaving open what to do with the edge case when the
difference goes below zero. You also need to remember
that subtraction is not commutative.
What kind of difference do you really mean?
Cheers
Manfred
|
|
|
|
|
http://yfrog.com/j227627210j i have this two images wanting to find either the difference or the similarities of the image and display the output in a pictureBox.
will this work?
or i have to convert image to bytes?
modified on Sunday, November 21, 2010 11:14 PM
|
|
|
|
|
You would need to do this pixel for pixel. Just iterate through all pixels in the image and substract them. Store the substraction result as pixel in a new bitmap of the same size as the two images you want to compare.
|
|
|
|
|
do you have an example? meaning example pixel(0,0) of image 1 minus pixel(0,0) of image 2?
|
|
|
|
|
public static Bitmap Diff(Bitmap src1, Bitmap src2, int x1, int y1, int x2, int y2, int width, int height)
{
Bitmap diffBM = new Bitmap(width, height, PixelFormat.Format24bppRgb);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
Color col1 = src1.GetPixel(x1 + x, y1 + y);
Color col2 = src2.GetPixel(x2 + x, y2 + y);
int r = 0, g = 0, b = 0;
r = Math.Abs(col1.R - col2.R);
g = Math.Abs(col1.G - col2.G);
b = Math.Abs(col1.B - col2.B);
int dif = 255 - ((r+g+b) / 3);
Color newcol = Color.FromArgb(dif, dif, dif);
diffBM.SetPixel(x, y, newcol);
}
}
return diffBM;
}
This code should create a greyscale image that shows the difference between two bitmaps. If you need more information, ask google. There's lots of information to be found about this topic.
|
|
|
|
|