|
Not a question, but something I learnt today that I'd like to share .
If I declare and initialise as follows...
<br />
string[] a,b,c;<br />
a = b = c = new string[size];<br />
a, b, and c all share the same memory location (i.e if you alter b - c and a are affected the same).
Something I should have spotted, but is all so easy to overlook with these fancy new languages.
.
Mark Brock
"We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen
Click here to view my blog
|
|
|
|
|
Exactly, because arrays in C# are reference types.
|
|
|
|
|
Someone might be mislead to believe that...
string[] a, b, c;<br />
a = b = c = new string[size];
would behave the same as...
int a, b, c;<br />
a = b = c = 10;
...which (as you discovered) it doesn't.
MarkBrock wrote: but is all so easy to overlook with these fancy new languages
...easy to overlook because it is poor style and easily misleading. To clearly show your intentions, it would have been better coded as either:
string[] a = new string[size];
string[] b = a;
string[] c = a; or
string[] a = new string[size];
string[] b = new string[size];
string[] c = new string[size];
...depending on what your intentions are.
|
|
|
|
|
I am using ApplicationDeployment in my project but i am getting error
The name 'ApplicationDeployment' does not exist in the current.
The name 'HttpUtility' does not exist in the current context.
I am not using namespace ? , if yes then what are the namcesapace for both of them.
|
|
|
|
|
What does the manual say for namespace
|
|
|
|
|
I seem to be struggling a bit creating a custom control. Just a plain ordinary custom control with some extra properties is no problem but when it gets a little more complex I'm stuck.
I am trying to make a fancy panel. All it is is a control with a panel in the centre while the space around the panel is used for drawing a border in.
So far so good. I can create a control with a panel in the middle and space around the sides for drawing a border but when the control is added to a form at deign time and I want to add controls into the panel, I have problems. The controls are being added to the control allright but not to the panel on the control. In other words, the new controls become child controls of my custom control exactly like the panel is a child control.
Any help please?
|
|
|
|
|
Add this attribute to your user control
[Designer("System.Windows.Forms.Design.ParentControlDesigner,
System.Design", typeof(System.ComponentModel.Design.IDesigner))]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
hi
i am writting a writer program that use XPBurncomponent.dll
a pice of code that i used is:
XPBurn.XPBurnCD cd = new XPBurn.XPBurnCD();
cd.AddFile(@"c:\pic1.jpg","pic1.jpg");
cd.RecordDisc(false, true);
but sometimes an error is shown :
error: Exception has been thrown by the target of an invocation
can anybody help me please?
M.Alizadeh
|
|
|
|
|
|
Hi all!!
I have a problem about my project. I want to add tag to files or directories and I have a problem about program start up.
in these code I can get full path but there is some problem about directories name.
For example:
C:\Documents and Settings\*****\Desktop\ListViewExample for this there is no problem
but
C:\Documents and Settings\*****\Desktop\List View Example but if a directory or file name have a space there is a problem occures like that :
C:\Documents and Settings\*****\Desktop\List\View\Example
I could not find a solution with for each too. How can I solve this problem? Thank you very much.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
namespace ARC
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args != null)
{
string FilePth = "";
for (int i = 0; i < args.Length; i++)
{
FilePth += args[i]+@"\\";
}
MessageBox.Show(FilePth);
if (FilePth != "")
{
parameter.FilePath = FilePth;
Application.Run(new Form1());
}
}
else
{
}
}
}
}
|
|
|
|
|
Any file path that has spaces in must be enclosed in double quotes "c:\ my path\xyz,txt"
Bob
Ashfield Consultants Ltd
|
|
|
|
|
I have am dynamically loading a web user control based on the click of a tab strip
I load the default control for the first tab in the page load event after checking page is not postback. After that the controls are loaded/unloaded based on the SelectionChanged event for the tab strip and again in Page load because with a dynamic load viewstate has to be reloaded. I have a datalist in the user control and I am trying to create the delegate so the parent can handle the click of the edit button in the user control. Honestly I am not very good at event delegation the code complies but I never get the command to execute on the parent
in the child control site.ascx I set up the datalist public event with code below
public partial class Site : System.Web.UI.UserControl
{
public delegate void myItemCommand(object source, DataListCommandEventArgs e);
public event myItemCommand dlSiteItemCommand;
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{ }
protected void dlSite_ItemCommand(object source, DataListCommandEventArgs e)
{
if (dlSiteItemCommand != null)
dlSiteItemCommand(source, e);
}
protected void Page_Load(object sender, EventArgs e)
{ //get the data and fill the datalist }
in the parent (Detail) I try to bind to the event in the Site.ascx When the page loads in the parent the procedure LoadUserControl()
is called and in it after I dynamically load the correct control, I caste the generic control to an instance of Site so I can see the public event I created. Thats where I have got it wrong I am SOOOOO confused. The binding does not work when I click the edit button in the child datalist I never break into the event that is bound on the parent Below is parent code. Please I not this is too long an explanation but I have been trying and reading a long time.
Cindy
public partial class Detail : System.Web.UI.Page
{
private string LastLoadedControl
{
get
{
return ViewState["LastLoaded"] as string;
}
set
{
ViewState["LastLoaded"] = value;
}
}
private void LoadUserControl()
{
string controlPath = LastLoadedControl;
if (!string.IsNullOrEmpty(controlPath))
{
PlaceHolder1.Controls.Clear();
UserControl uc = (UserControl)LoadControl(controlPath);
if (controlPath == "Site.ascx")
{
Site ucSite = (Site)uc;
ucSite.dlSiteItemCommand += new Site.myItemCommand(ucSite_dlSiteItemCommand);
}
PlaceHolder1.Controls.Add(uc);
}
}
void ucSite_dlSiteItemCommand(object source, DataListCommandEventArgs e)
{
(source as DataList).EditItemIndex = e.Item.ItemIndex;
(source as DataList).DataSource = dsTunnel;
(source as DataList).DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{}
protected void Page_Load(object sender, EventArgs e)
{
if(!(Page.IsPostBack))
{
string controlPath = null;
controlPath = "Site.ascx";
LastLoadedControl = controlPath;
LoadUserControl();
}
LoadUserControl();
}
private void ts_SelectionChanged(object sender, JQD.TabStrip.SelectionChangedEventArgs e)
{
int TabPos = e.TabPosition;
ActiveTab = TabPos;
string controlPath = string.Empty;
switch (TabPos)
{
case 0:
controlPath = "Site.ascx";
LastLoadedControl = controlPath;
LoadUserControl();
break;
case 1:
break;
}
|
|
|
|
|
Trying to use the random() to generate random words from a string[],now I want to put the already picked words in may be an array so that the random() should not pick that word if once picked before.please help
|
|
|
|
|
Random helper class...[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Thats was really a great prog.
Now check here, am generating a random word from an array which I display on the textbox in form of stars for the user to guess.Now I don't want the user to come across the same word again.How can I please go about it to make the random method not to get the same word again.Like the way Hung man game operates
waiting......
|
|
|
|
|
Read the question before you reply. It's not helpful to post your self-promoting links if they don't apply to the question at all.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
If you do that, you have to loop when you try to find an unused word. Instead, put the words in a list, and remove the words that are picked:
List<string> words = new List<string>(arrayOfWords);
Random rnd = new Random();
int index = rnd.Next(words.Count);
string pickedWord = words[index];
words.RemoveAt(index);
Despite everything, the person most likely to be fooling you next is yourself.
modified on Sunday, September 7, 2008 11:17 AM
|
|
|
|
|
That was quiet penetrating, which namespace do I use for Lists. Is it an ArrayList or SortedList you are talking about(am familiar with these System.Collections;, System.Text;)?
|
|
|
|
|
The List<T> class is in the System.Collections.Generic namespace.
Unless you are stuck with framework 1.x you should not use ArrayList at all.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks.
Unfortunatly, am only able to program on one form.How about having multiple forms and calling them interchangebly.
|
|
|
|
|
MorganSim wrote: Unfortunatly, am only able to program on one form.How about having multiple forms and calling them interchangebly.
I don't see how this relates to the original question at all? Can you clearify?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hello people!!!
was just trying to see what else the internet can provide to the real world, unfortunatly, I arrived down to this site.It must be great site.
Am just new into C# programming, no much exprience, I would love to be given to write a simple program just to test how far I can go with C#.Please help,send back specifications for a small program I must write.Please!!
|
|
|
|
|
Check this link.[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
|