|
leppie wrote: ever so slight
It's a good rule of thumb but one that can be ignored (carefuly) if the structure is only using integral types (as in the OP's) or other structs that only contain integral types. Take the Size struct as an example. It's not immutable, but a struct makes perfect sense and using it within your own struct would be good 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)
|
|
|
|
|
DaveyM69 wrote: Take the Size struct as an example. It's not immutable, but a struct makes perfect sense and using it within your own struct would be good too.
The Size struct is not a very good example, just because it's mutable.
If you need a type that is mutable, you should use a class, not a struct. It's so easy to accidentally change a copy of the struct instead of the struct.
As I am sure that you know, to safely change a property in a struct in an array you would have to:
NodeModuleLevelStruct temp;<br />
temp = theArray[42];<br />
temp.IsActive = true;<br />
theArray[42] = temp;
With a class, you can just do:
theArray[42].IsActive = true
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Yeah - and that's exactly why I like to use them - only when appropriate of course.
I can work on the copy, make any changes I like and then just forget the whole thing if I don't want/need to commit them. If it's a class, to have that flexibility you have to implement some sort of cloning method and work on the clone, then you still have to remember to reassign.
I know where you're coming from, and agree to a point, but the blanket statement that if it's mutatble you should use a class, whilst it may prevent errors, isn't strictly true IMHO.
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)
|
|
|
|
|
DaveyM69 wrote: I can work on the copy, make any changes I like and then just forget the whole thing if I don't want/need to commit them. If it's a class, to have that flexibility you have to implement some sort of cloning method and work on the clone, then you still have to remember to reassign.
I see your point, and that would work as long as it's only you who work with the code. If someone else has to take over your code, they can easily be fooled by this uncommon usage of structs.
A struct is a value type, and the semantics of a value type is to represent a single value of some kind. If you have several distinct values in a struct it doesn't behave as a value type any more, and you should use a class instead.
Also, a struct should not be larger than 16 bytes. A small struct can be copied using only a pair of machine instruction, while a large struct requires a loop to copy the memory area each time.
It's easier to use a struct for cloning instead of implementing proper cloning for a class, but you get worse performance.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: a large struct requires a loop to copy the memory area each time.
It's easier to use a struct for cloning instead of implementing proper cloning for a class, but you get worse performance.
I've read alot on this, especially today, and those two points I didn't come accross anywhere! Valid and noted.
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)
|
|
|
|
|
I have all my data in MySQL as char data type in "en" locale.
That means all int and float and double type data are stored
as char data without thousand separator, but float and double data have
ofcourse with decimal (.) separator.
My question is : How can I display those data according to program's locale
setting. Since the data already in char type I could not find out a smouth
way to display the data returned from database accordingly. My program can change
the locale settings at run time according to user request.
By the way I use DataGridView for the display control on my win form.
Thanks,
Muharrem
|
|
|
|
|
Use one of the TryParse overloads for the data type that you need to display.
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)
|
|
|
|
|
hi
i have a code that does not response
dataGridview1.DataSource = dataset1;
i`m sore that dataset is fill
and when i use following code dbgrid creates as same record number as exist
in dataset but the value of rows in dbgrid are empty
dataGridview1.DataSource = dataset1.Tables[0];
|
|
|
|
|
Hi,
try to use the datagridview1.DataBind() method to finally bind the dataset to the datagridview.
Regards
Sebastian
|
|
|
|
|
Hi,
That´s not working? error not there
reza assar wrote: dataGridview1.DataSource = dataset1.Tables[0];
Datatable as to be empty! if you have only 1 databable in the dataset, just create the table. Bellow i didn´t create a dataset.
Change the routine code to fit your demands.
public static void DataGridView_Fill(DataGridView dgv, string store_procedure)
{
SqlConnection sql_conn = new SqlConnection(connection_string);
SqlCommand sql_cmd = new SqlCommand();
sql_cmd.Connection = sql_conn;
sql_cmd.CommandText = store_procedure;
sql_cmd.CommandType = CommandType.StoredProcedure;
sql_conn.Open();
SqlDataAdapter sql_da = new SqlDataAdapter();
sql_da.SelectCommand = sql_cmd;
DataTable dt = new DataTable();
sql_da.Fill(dt);
sql_conn.Close();
dgv.DataSource = dt;
}
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
hi
what can i do to have a shortcut for click event of a LinkLabel
|
|
|
|
|
Shortcut to what?
Web page / program etc... use System.Diagnostics.Process.Start method.
[Edit]The tag property of the linklabel can be a useful place to store your URL or path etc... you'll have to cast back to string to retrieve the data.[/Edit]
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)
|
|
|
|
|
Im generating a Pdf of a table that contains about 200 000 records, each containig a differen image file too. so my pdf has to draw 200 000 little images, i get out of memory erro or GDI+ error after a while. The code does work for less records (checked on 100 - 1000). the code also works if I delete the image = new PdfBitmap("path for a different image for every cell of the table"); line and draw the same image in every row.
Please any suggestions would be appreciated.
public PdfImage image = new PdfBitmap("l.jpg");
void table_EndCellLayout(object sender, EndCellLayoutEventArgs args)
{
int cellIndex = args.CellIndex;
if ((cellIndex == 5) )
{
PdfGraphics g = args.Graphics;
try
{
image = new PdfBitmap("path for a different image for every cell of the table");
RectangleF bounds = args.Bounds;
PointF point1 = bounds.Location;
//obliczanie srodkowego punku komorki
g.DrawImage(image,point1.X, point1.Y, 30, 30);
}
catch
{
}
}
}
|
|
|
|
|
You should be disposing of any 'new' disposable instances you create, ie PdfBitmap.
That said, I have never seen that class, and there could be other issues involved.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - coming soon ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
I have tried that but maybe Im not doing it right
I cant do image.dispose(). tried
image=null;
and then calling garbage collector..
Im a begginer c# programmer, pls could u write the ideas u have in code?
|
|
|
|
|
hello,
i want to show 5 days before current date and 20 days after current date in a calender control with every date link to a particular page.
plz give me any sample code.
regards
aurosikha
|
|
|
|
|
Windows Forms does not have a Calender control (it does have DateTimePicker), so I suggest you head off to the ASP.NET message board.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - coming soon ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
I know how to insert images to PDF but i need to how can we insert image and image name below it in PDF using C# or Vb or VB.net
RamyaNaidu
|
|
|
|
|
Contact the supplier of your PDF library.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - coming soon ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
|
Use an interface. Simple example below.
public interface IMyInterface
{
void WriteMe();
}
public class A : IMyInterface
{
public void WriteMe()
{
Console.Write("A");
}
}
public class B : IMyInterface
{
public void WriteMe()
{
Console.Write("B");
}
}
public class C : IMyInterface
{
public void WriteMe()
{
Console.Write("C");
}
}
public class D
{
public void WriteParameter(IMyInterface test)
{
test.WriteMe();
}
}
Then you can do this
D d = new D();
d.WriteParameter(new A());
d.WriteParameter(new B());
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)
|
|
|
|
|
Thanks a lot Dave this code worked for me.
|
|
|
|
|
If I understand what you want (and I probably don't), what you want to do is called oveloading.
public class A
{
private List<a> list = new List<a>();
public List<a> GetAllRecords() { get { return list; } }
}
public class B
{
private List<b> list = new List<b>();
public List<b> GetAllRecords() { get { return list; } }
}
public class C
{
private List<c> list = new List<c>();
public List<c> GetAllRecords() { get { return list; } }
}
public class D
{
private A a = new A();
private B b = new B();
private C c = new C();
private List<a> aList;
private List<b> bList;
private List<c> cList;
public D()
{
}
private List<a> GetAllRecords(A a)
{
aList = a.GetAllRecords;
}
private List<b> GetAllRecords(B b)
{
bList = b.GetAllRecords;
}
private List<c> GetAllRecords(C c)
{
cList = c.GetAllRecords;
}
}
[EDIT] Forgot to convert the pointy brackets...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Saturday, October 11, 2008 5:08 AM
|
|
|
|
|
Hello friends,
I'm using Visual Studio 2005. I'm developing an application that extracts icons from .exe and .scr files and saves them into a MS-Access database. I've created a OLE Object field in the database table for the icons. I use the Icon.Save() along with an instance of the MemoryStream class to get raw icon data bytes into an array. My problem is that Icon.Save() method saves the icon as a 16-color image. I want to know how can I save the icon with no quality loss.
Also, are there any alternatives to the MemoryStream class?
Many thanks in advance.
|
|
|
|
|
hi
this is a good example for loading and saving icons.
http://www.codeproject.com/KB/cs/IconLib.aspx
regards
|
|
|
|