|
Hi Shah
Indexers allows you to access the object like you are accessing the array .
Indexers permit instances of a class or struct to be indexed in the same way as arrays. Indexers are similar to properties except that their accessors take parameters
<br />
class SampleCollection<T><br />
{<br />
private T[] arr = new T[100];<br />
public T this[int i]<br />
{<br />
get<br />
{<br />
return arr[i];<br />
}<br />
set<br />
{<br />
arr[i] = value;<br />
}<br />
}<br />
}<br />
<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
SampleCollection<string> stringCollection = new SampleCollection<string>();<br />
stringCollection[0] = "Hello, World";<br />
System.Console.WriteLine(stringCollection[0]);<br />
}<br />
}<br />
<br />
<br />
Indexers enable objects to be indexed in a similar way to arrays.
A get accessor returns a value. A set accessor assigns a value.
The this keyword is used to define the indexers.
The value keyword is used to define the value being assigned by the set indexer.
Indexers do not have to be indexed by an integer value; it is up to you how to define the specific look-up mechanism.
Indexers can be overloaded.
Indexers can have more than one formal parameter, for example, when accessing a two-dimensional array.
Thanks and Regards
Sandeep
If you want something you never had,
do something you have never done!
|
|
|
|
|
I had problem with listbox in c#:
the problem is i have to listboxes the items in listbox1 moves to listbox2
and next button is pressed it moves to the nextpage if the items in listbox2 are moved back to listbox1 and next button is pressed it should show error message. upto here the functionality is working fine
the problem is there is a link below to delete the items in listbox1
once i deselect the items in listbox2 and then delete the items in listbox1
and press the nextbutton the message is not fired instead it is navigating to the next page.
I used javascript for moving the selected items from listbox1 to listbox2 and for deleting the items in listbox1
i require solution to this problem
any one please help me out in solving this problem
Thanks ®ards
giribabu
hi
|
|
|
|
|
Check your logic on next buttion click there might be any problem can you post the javascript
Thanks and Regards
Sandeep
If you want something you never had,
do something you have never done!
|
|
|
|
|
Hi all,
i cant get the Web control Link button to be displayed in a html tag,
I got an a display msg "System.Web.UI.WebControls.LinkButton " cos it is converted to a string in my below codin.
How do i convert the lbtn linkbutton below so that it could appear as expected?
LinkButton lbtn = new LinkButton();
lbtn.ID = file.ServerRelativeUrl;
lbtn.Text = "Check Out";
lbtn.Command += new CommandEventHandler(testButtonClick);
lbtn.CommandName = file.Name;
lbtn.CommandArgument = file.ServerRelativeUrl;
string curFile = "<A HREF='" +
SPEncode.HtmlEncode(file.ServerRelativeUrl) + "'>" +
SPEncode.HtmlEncode(file.Name) + "</A>";
s += "<div id=x_" + i + "_" + j +
" style='margin-top:2;margin-right:" + Indent + ";margin-left:" + Indent + "' " + " onclick='showHide(window.event," + j + ");'";
s += " style='display:none'>";
s += "<font color=" + othersColor + " face=Wingdings>" + "</font> " + lbtn + " " +curFile;
s += "</div>";
Thanks in Advance!
minlynn
|
|
|
|
|
You can't like this way
lezahtiek wrote: s += "" + " " + lbtn + " " +curFile;
You have to add the control to the page
Do one thing Add one place holder where you want to show the Link button then in the code add the button dynamically bu
Placeholder.Controls.add(linkButton);
i think this will help you
Thanks and Regards
Sandeep
If you want something you never had,
do something you have never done!
|
|
|
|
|
please take a look at the below link:
http://i169.photobucket.com/albums/u228/hazel_nut_622/webpart.jpg
i need to add the button dynamically beside each of the file name, for example a check out button beside "New Text Document.txt"
what you see in this link are all generated at a go, for a web control button it will be displayed outside of this whole part.
More source code;
SPFileCollection files = folder.Files;
foreach (SPFile file in files)
{
LinkButton lbtn = new LinkButton();
lbtn.ID = file.ServerRelativeUrl;
lbtn.Text = "Check Out";
lbtn.Command += new CommandEventHandler(testButtonClick);
lbtn.CommandName = file.Name;
lbtn.CommandArgument = file.ServerRelativeUrl;
string curFile = "<A HREF='" +
SPEncode.HtmlEncode(file.ServerRelativeUrl) + "'>" +
SPEncode.HtmlEncode(file.Name) + "</A>";
s += "<div id=x_" + i + "_" + j +
" style='margin-top:2;margin-right:" + Indent + ";margin-left:" + Indent + "' " + " onclick='showHide(window.event," + j + ");'";
s += " style='display:none'> ";
s += "<font color=" + othersColor + " face=Wingdings>" + "</font> " + lbtn + " " +curFile;
s += "</div>";
}
really need some help!
thanks alot in advance.
minlynn
|
|
|
|
|
Please note, I am still learning!
I have a class that holds information about an object. I have another class that I would like to manage a collection of those objects. What I am trying to do is when a user updates some values for an object, that the manager then resorts the order of the collection automatically. I would also like to include an ability to 'lock' the sorting so a user could do a batch of changes and then sort at the end. I was looking at delegates, but I am not sure they are what I need. In fact, I am not even sure that what I want to do is really possible. Here is a basic example of what I am trying to do:
class cThing
{
private float _depth;
public float Depth
{
set
{
_depth = value;
}
}
}
class cThingManager
{
public List<cThing> MyThings = new List<cThing>();
public void Sort()
{
MyThings.Sort();
}
}
I would imagine this is possible, but I don't know what it would be called so I've been having a hard time searching for information on this. Any help is appreciated!
Edit - I figured out how to do the locking!
-- modified at 22:50 Thursday 3rd May, 2007
|
|
|
|
|
You could add an event to your cThing class (maybe called DepthChanged) that is fired whenever the depth changes. You're manager has to subscribe an event handler to the event of each item it manages and inside the event handler sort the list, if sorting is not locked.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
are you asking how to sort on a custom object? or how to have a child class call a method on a parent class?
|
|
|
|
|
1) Your "class to be sorted" should implement IComparable<t> interface with you T = your class name.
2) You should add an event handler to fire property change events of your "class to be sorted" objects
3) Catch these events in your collection and use Array.Sort(myCollection)
OR
1) you can use a SortedList<tkey, tvalue=""> or SortedDisctionary<tkey, tvalue=""> as the collection of your "class to be sorted" objects and set TKey to the property of your "class to be sorted" but this property should be IComparable!
2) then when this property changes, your collection is automatically sorted
BUT these 2 options fails in your need to do a batch update and then sort + the ability to lock sorting, SO:
1) You should use a BatchUpdate after a number of updates are done for any "class to be sorted" object by keeping a int _updatecount static property in your Collection which is increased by each update to any of your object( if you use my 1st way, then you can increase this value in the property change event handler in your collection )
OR
2) The easiest and best way, do whatever update you want, then call Array.Sort(myCollection) where myCollection is ICollection
Hope this helps...
|
|
|
|
|
I'm putting together a program from various sources, like getting the thumbnail of a Window, and capturing window images using their handles.
However, all the sources that I've found so far are facing the same problem: When capturing the image of a particular Window using its handle, only the client area of the window shows up in the image. The glass title bar and border etc just show up blank. What is causing this problem? Is there a different way to do it on Vista where the entire Window is correctly captured?
Thanks.
|
|
|
|
|
Hi!
i'm trying to convert an image object to string and later bring it back from the string..
My code:
<br />
Image image = Image.FromFile(@"C:\08.jpg");
byte[] obj;<br />
<br />
using(MemoryStream ms = new MemoryStream()) {<br />
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
obj = ms.ToArray();
}<br />
<br />
string str = System.Text.Encoding.ASCII.GetString(obj);
<br />
<br />
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(str);
<br />
Image newImage;<br />
using(MemoryStream ms = new MemoryStream(bytes))<br />
newImage = Image.FromStream(ms);
in the *** line an exception ArgumentException "Parameter is not valid." is thrown..
if in the *#* line i change from Jpeg to Bmp the exception is not thrown but the image is scrambled..
thanks for any help!!
life is study!!!
|
|
|
|
|
Hi,
it is OK to use a byte[] to hold an image.
it is not OK to try and put that byte[] into a string, unless some
special conversion is applied that ensures a normal string results.
Possible encodings are HEX (which expands each byte to 2 chars,
and base64 (see Convert.To/FromBase64String() methods).
|
|
|
|
|
That's it!! Thanks a lot!!!
life is study!!!
|
|
|
|
|
Look at the BitConverter class, BitConverter.ToString Method (Byte[]).
http://stefanprodan.wordpress.com
|
|
|
|
|
thanks, but there is no overload for GetBytes(string s) in BitConverter class..
life is study!!!
|
|
|
|
|
Here is my code, I've test it with BMP but I think it will work with any image format.
<br />
using System.IO;<br />
using System.Drawing;<br />
using System.Runtime.Serialization.Formatters.Soap;<br />
<br />
Image image = Image.FromFile(file);
SoapFormatter formater = new SoapFormatter();<br />
byte[] obj;<br />
using (MemoryStream ms = new MemoryStream())<br />
{<br />
formater.Serialize(ms, image);<br />
obj = ms.ToArray();<br />
}<br />
<br />
string str = Convert.ToBase64String(obj);
<br />
byte[] bytes = Convert.FromBase64String(str);
<br />
Image newImage;<br />
using (MemoryStream ms = new MemoryStream(bytes))<br />
{<br />
newImage = (Image)formater.Deserialize(ms);<br />
}<br />
<br />
newImage.Save(file + ".bmp");<br />
http://stefanprodan.wordpress.com
|
|
|
|
|
if you use "using keyword" then the MemoryStream, which is in this case your raw image data, disposed. Copy the ms.ToArray() to a new byte[] by Array.Copy(...) method before you exit "using(...) block".
Hope this helps...
|
|
|
|
|
Hi All
I've just joined a project that is going to require a heavy load of optimization. I'm looking for a language that is compatible with C# that compiles into machine code. At the moment, our plan involves a number of nested loops to which we are hoping to write in machine code. Would C++ work for this? Thanks.
|
|
|
|
|
If you look inside a C++ application, there is a lot of overhead and name mangling that goes on. This can lead to loss of performance, but not necessarily. If you are looking to use a third generation language with close to optimal speed, then your best bet is C. If speed is an absolute must, then you need to look at assembly.
Something to keep in mind also is the balance between speed and memory optimization.
Phil
|
|
|
|
|
If you mean C# compiled to machine code, look at the Mono project.
|
|
|
|
|
How does mono compile C# to machine code exactly?
|
|
|
|
|
heavy load of optimization = ANSI C
http://stefanprodan.wordpress.com
|
|
|
|
|
Any .NET language is compatible. In fact there are other languages compatible, callable from managed (.NET) languages but that requires experience in these areas and I don't suggest it because no language is 100% compatible with another one 
|
|
|
|
|
Is there such a thing as an infinite array in c#?
If not, does C# give the concept of vectors.
|
|
|
|