|
Out of interest I googled C# Ascii art - Loads of hits, including articles with code at CodeProject.
Hope that helped.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
I have a class which has a dictionary and I don't want to reveal this information to the outside. So I simply made it a private member. I want people to enumerate through my class so I did the following:
public class CustomerCollection : IEnumerable<KeyValuePair<string, Customer>>
{
#region IEnumerable<KeyValuePair<string,Store>> Members
public IEnumerator<KeyValuePair<string, Customer>> GetEnumerator()
{
return this._districts.GetEnumerator();
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
return this._districts.GetEnumerator();
}
#endregion
}
This works fine but during enumeration, the client has to write code as below:
foreach (KeyValuePair<string, Customer> c in this._customers) // _customers is an instance of CustomerCollection
{
c.Value.Name = "Whatever";
}
What should I do if I want the client to be able to do this:
foreach (Customer c in this._customers)
{
c.Name = "whatever";
}
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
Have CustomerCollection contain a list of Customer objects
So your code should look something like this.
NOTE: this is not tested and probably wont compile
<code>
public class Customer
{
public string Name{get; set;}
...
}
public class CustomerCollection : CollectionBase
{
public Customer this[int index]{
get{ return innerList[index];}
set{ innerList[index] = value;}
}
public void Add(Customer item){
innerList.Add(item);
}
}
</code>
If you inherit CollectionBase (System.Collections.Specialized i think) you don't to inherit or even implement IEnumerable because CollectionBase does all the dirty work for you.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
I don't want to inherit because I want to hide the interface of the inner collection. Also, I want this to be a readonly collection.
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
I've never tried it, but it might work if you can provide an implicit conversion operator from Customer to KeyValuePair<string, Customer> although intellisense will still show as wanting a KeyValuePair so it wouldn't be intuitive.
You may need to wrap the dictionary a little more to provide a different enumerator.
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,
If you expose the Dictionary's value collection you will get this functionality.
Dictionary<string, Customer> dic;
ICollection<Customer> Customers {
get { return this.dic.Values; }
}
I think that's all you need as the value collection is enumerable.
Alan.
|
|
|
|
|
CodingYoshi wrote: What should I do if I want the client to be able to do this:
foreach (Customer c in this._customers)
{
c.Name = "whatever";
}
How about this?
public class CustomerCollection : IEnumerable<Customer>
{
public IEnumerator<Customer> GetEnumerator()
{
foreach(KeyValuePair<string,Customer> item in _districts)
yield return item.Value;
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
|
|
|
|
|
Thanks! That is exactly what I am looking for. I will give that a try and let you know if it works; although, it looks as it should.
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
could someone point out what I am doing wrong that the reportProgress method is not working.
BackgroundWorker bw = new BackgroundWorker();
public Control()
{
bw.WorkerReportsProgress = true;
bw.WorkerSupportsCancellation = true;
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
}
void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
//do updates
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
if ((worker.CancellationPending == true))
{
e.Cancel = true;
}
else
{
//work code removed
totalnumbersoffiles = XmlFiles.Count;
for (int filecount = 0; filecount < XmlFiles.Count; filecount++)
{
//work code removed
bw.ReportProgress(filecount);
}
}
}
|
|
|
|
|
Not sure what's wrong with your code - this sample code below works though so compare the two.
public class Test
{
private BackgroundWorker backgroundWorker;
public Test()
{
backgroundWorker = new BackgroundWorker();
backgroundWorker.WorkerReportsProgress = true;
backgroundWorker.WorkerSupportsCancellation = true;
backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
}
public void StartTest()
{
backgroundWorker.RunWorkerAsync();
}
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
Console.WriteLine(e.ProgressPercentage);
}
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i <= 100; i++)
backgroundWorker.ReportProgress(i);
}
private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Console.WriteLine("Done");
}
}
Test t = new Test();
t.StartTest();
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)
|
|
|
|
|
Planker wrote: totalnumbersoffiles = XmlFiles.Count;
for (int filecount = 0; filecount < XmlFiles.Count; filecount++)
{
//work code removed
bw.ReportProgress(filecount);
}
This looks odd to me.
|
|
|
|
|
instead of
bw.ReportProgress(fileCount)
write
worker.ReportProgress(fileCount+1)
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
Hi,
I want to change Crystal Reports Details section(Section3) height in code behind with C# or VB.NET.
Help me...
|
|
|
|
|
Hello everybody,
first I want to tell you that I don't know C# - I'm programming in VB.NET which works for most things I need. Now I have the need to extend a working C# class with a method that converts an RGB Array to its rows, which I did in VB first and had it translated to C# in order to implement.... BUT: The translation from SharpDevelop, which seemed to work fine, is not recognized by the Visual Studio compiler.
Maybe someone of you could help me find what's wrong? Here's the translation from SD:
public int[] FromArray(Array RGBArray)
{
int[] returnValue = new int[imageHeight];
for (int i = 0; i <= returnValue.Length - 1; i++)
{
for (int j = 0; j <= imageWidth; j++)
{
returnValue[i] = SetRow(i, RGBArray(j));
}
}
return returnValue;
}
The compiler tells me "RGBArray is a Variable but is used like a Method"
Thank you for helping out,
Mick
|
|
|
|
|
Michael Schäuble wrote: returnValue[i] = SetRow(i, RGBArray(j));
The code spinet might should be:
<br />
returnValue[i] = SetRow(i, RGBArray.GetValue(i,j));<br />
RGBArray(j) is VB.NET style indexer,not C#.System.Array type doesn't have any indexers defined so to get a value an position j you shoud use GetValue method and to set value just call System.Array.SetValue(object,params[] indexes) method.
[EDIT]
Are you sure that j index is not outside of RGBArray?
Life is a stage and we are all actors!
modified on Tuesday, August 25, 2009 4:01 PM
|
|
|
|
|
Thank you for the support, Hristo!
You were right regarding 'other problems' in the code... I changed it to
public int[] FromArray(Array RGBArray)
{
int[] returnValue = new int[imageWidth];
for (int i = 0; i < imageHeight; i++)
{
for (int j = 0; j < imageWidth; j++)
{
returnValue[j] = (int) RGBArray.GetValue(j);
}
SetRow(i, returnValue);
}
return returnValue;
}
Would you agree with that?
modified on Tuesday, August 25, 2009 4:15 PM
|
|
|
|
|
In order to avoid confusing with array indexing you would better use i < imageHeight instead of i <= imageHeight -1 .
Life is a stage and we are all actors!
|
|
|
|
|
Just had corrected that obviously while you were posting.
Thanks for your help and have a nice evening!
|
|
|
|
|
Always glad to help to someone!
Life is a stage and we are all actors!
|
|
|
|
|
Hi,
I am working with C# .net. I have created a software application and the application works fine. But I am not able to launch my product as the .net framework is creating a problem. My application size is just 1MB but the framework makes it heavy. No user would like to download 30 MB from internet to run the application.
I don't understand Microsoft says the VS is framework independent then why a C# application installer needs framework.
Is there a way to remove the dependency?
Looking forward to hear a solution.
Thanks in advance
|
|
|
|
|
No, Target machine must have DNF else application wont launch. And these days almost every pc have DNF installed and even if not then your application must enough useful and attractive to force user to install DNF. But if you're selling your app then you can provide a setup of DNF alongwith the installation disk.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Waheed Ur Rehman wrote: I don't understand Microsoft says the VS is framework independent then why a C# application installer needs framework.
Managed code is not dependant of VC redists so this avoids the DLL hell.It could be ported to another OS like Linux or MAC and with almost zero touch.So .NET code is much more safer and easy to deploy than unmanaged C/C++ code.NET runtime by default is part of Vista ,Windows 7 and Windows Server System(2003,2008) and XP soon will be marked as depricated,so you needn't to worry about .NET dependencies.
Life is a stage and we are all actors!
|
|
|
|
|
Is there no solution to remove DNF 2.0 from the application. The issue is the resulting size of the application. If I embed DNF or make the user to download and install from the web the application size increases more than 20 times of the actual size of the application.
|
|
|
|
|
No. No more than you can write an MFC/VB6 application that doesn't depend on the MFC/VB6 rumtime being installed.
There is software that will compile the needed parts of the framework that are written in .net into your executable and package up the parts of the framework that are written in C++ so that the framework doesn't need to be installed. The result will be several dozen megs in size, and is probably not worth it unless you're targetting the 3.0/3.5 frameworks which are several hundred megs in size. The tools to do this also cost upwards of $1k.
Any user running a new version of windows (Vista or Later) will have 2.0 framework. IIRC w7 comes with the 3.5 framework. Any user who runs windows update in automatic mode and is running win2k or later will have the 2.0 framework, if running XP or later the 3.5 framework. That's probably >99% of windows PCs on the market. To target the rest your choices are to make them DLing a framework/runtime, or rewrite your app in pure win32 C code which calls the win32 API directly.
The latest nation. Procrastination.
|
|
|
|
|
I've set MaximizedBounds when Form's state is Maximized but that doesn't effect the form at all. I tried to set ClientSize, Size, Bounds... but nothing works. I've got a working way that is
this.WindowState = FormWindowState.Normal;
this.WindowState = FormWindowState.Maximized;
but thats raising some not required custom events and form flicks...any better way you guys know ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|