|
The actual string array does not have an IndexOf method, but the Array class has a static (and generic) IndexOf method.
string[] foo = new string[] { "a", "b", "c" };
int index = Array.IndexOf<string>(foo,"b");
|
|
|
|
|
string[] arrNames = new string[] {"a", "b", "c", "d", "e", "f"};
string status = (arrNames.Contains("b")) ? "Found" : "Not Found";
"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
|
|
|
|
|
Ew, that smells of Extension Method.
|
|
|
|
|
I don't know if it is or not, but it fits his requirements of finding out if "b" is in the array without using a loop.
"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 Wednesday, October 15, 2008 9:13 AM
|
|
|
|
|
Array.IndexOf(arrNames, "b") will give the index or -1 if its not there
((System.Collections.IList)arrNames).Contains("b") will give a true or false
Chas
|
|
|
|
|
bool found = Array.Exists(arrNames, s => s == "b");
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - coming soon ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Hello
I have a requirement that I need to show the vacaation plans of the Employees in the form of Gannt Chart. For that i need to implment custom calendar which can show different kinds of views like Monthly,weekly etc.
Can any body suggest good design for this in developing the user control, If any body know free custom calendar available already, kindly let me know.
Best Regards
Shankar
|
|
|
|
|
I am not aware of any free third-party controls that you could use. However, this sounds like it could be a VSTO project that integrates into MS Outlook 2007 (or 2003 if you haven't upgraded yet). Then you have the full capabilities of Outlook while still allowing your own custom logic and information.
Unfortunately I can only suggest this, I have not worked with VSTO so I would be unable to suggest anything more. Hopefully this leads you in the right direction though.
Regards,
Thomas Stockwell
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.
Visit my Blog
|
|
|
|
|
I have a DataSet table column which I wish to populate with the value from a databound combobox
So far my thoughts have been along the lines of:
DataRowView debtor = (DataRowView)BindingContext[debtorDataSet, debtor"].Current;<br />
DataRowView keyEvent = (DataRowView)BindingContext[debtorDataSet, "DebtorKeyEvents"].Current;<br />
keyEvent["KeyEventCode"] = ((DataRowView)this.KeyEventTypeComboBox.SelectedValue).Row[this.KeyEventTypeComboBox.ValueMember];
but, without success.
Whare am I going wrong please?
|
|
|
|
|
I figured it out and used:
DataRow dr;
dr["KeyEventCode"] = this.KeyEventTypeComboBox.SelectedValue;
|
|
|
|
|
Hi,
I am using NHibernate to persist my objects. To delete an object from DB I have written the below code : I have checked my DB too and it has records.
public void Delete<T>(T item)
{
try
{
using (ISession session = factory.OpenSession())
{
using (session.BeginTransaction())
{
session.Delete(item);
<b>session.Transaction.Commit();</b> //Code is breaking here.
}
}
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
System.Windows.Forms.MessageBox.Show(e.StackTrace);
}
}
The code is breaking at line session.transaction.commit(); with following error message
"Unexpected row count: 0; expected: 1"
Please let me know how to fix this.
Thanks in Advance
Regards
Puneet
|
|
|
|
|
Hi,
long time that I did something with hibernate, but I think the problem is, that the item you want to delete is associated with another session. Try to refresh the item with the new session before you delete it (this is not the best way to do this, it is just a quick-and-dirty solution).
...
session.Refresh(item);
session.Delete(item);
...
Please let me know if this fixed your problem.
Regards
Sebastian
|
|
|
|
|
Dear all,
I'm using two web browsers one has a url to a document the other edits one of the first browser element then I replace the inner html of that element by the edited one the problen is that when replacing the inner html the path of the images changes to be the full image path instead of being like this "../images/Logo.gif" although this is the form of the path in the second browser.
I want to know how can I keep the path in the short mode between the replace operation?
Thanks.
Dad
|
|
|
|
|
Hi Guys,
I am very new to Log4Net. I need to log some logging statement in SQL Server DB. How to add the logging stmt programmatically?
I google it out for few sample, but didn't find, wht I want.
Plz help out.
Thanks,
Chintan(India)
|
|
|
|
|
|
Hi
How do you link a treeview and a list view so that when i click on the treeview it will display what node i have clicked on the List View?
Does any one Know how to do this ?
Please Help ME
|
|
|
|
|
|
Hi all,
I have the following method that was wriiten in C. The method makes use of a MarshallSoft method called: cscGetData(vSock, Buffer, BufLen) . I am trying to rewrite the method in C#. Here is some info about the cscGetData method:
The cscGetData function is used to receive data from an established connection. All available data is copies to 'Buffer' up to a maximum of 'BufLen'. cscGetData never waits for data.
So the problem is that the C# method does not work. What am I doing wrong ...
C version of GetData Method
Code = GetData(i, DataSock, (char *)gConnectData[i].Request, STRING_SIZE);
int GetData(int Connect,int Sock, char *Buffer, int BufLen)
{int Code;
Code = cscGetData(Sock, Buffer, BufLen);
if(Code<0)
{DisplayError(Connect, Code, (char *)"cscGetData:");
gConnectData[Connect].ConnectState = STATE_FINI;
}
return Code;
}
C# version of GetData Method
Code = TcpServer.GetData(i, TcpServer.ListenSocket, TcpServer.connectData[i].Request, 128);
unsafe static public int GetData(int Connect, int Sock, string Buffer, int BufLen)
{
int Code;
char[] BufferString = Buffer.ToCharArray();
fixed (char* pBuffer = BufferString)
{
cscShortToByte(pBuffer);
}
fixed (char* pBuffer = BufferString)
{
Code = cscGetData(Sock, pBuffer, BufLen);
if (Code < 0)
{
connectData[Connect].ConnectState = (int)STATE.STATE_FINI;
}
}
return Code;
}
Many thanks in advance
Kind regards,
The only programmers that are better those C# programmers are those who code in 1's and 0's |
Programm3r
My Blog: ^_^
|
|
|
|
|
A char in C corresponds to a byte in C#.
A char in C# is a 16-bit unicode character.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi,
Thanks for your response. I do not wish to sound ungrateful, but what does this have to do with the methods?
Kind regards,
The only programmers that are better those C# programmers are those who code in 1's and 0's |
Programm3r
My Blog: ^_^
|
|
|
|
|
You are declaring an array of characters, and the method is writing to it as if it was an array of bytes. You are putting the wrong data type in the array, so you are only using it as a dumb memory area.
Declare an array of bytes instead, then you don't need the marshalling method in an unsafe code block to read the char array as a byte array. You can use a regular Encoding.Default.GetString call.
Also, you are changing the contents of a string, which is a big no-no. Strings are immutable, and all code that uses strings rely on that.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for the response.
The only programmers that are better those C# programmers are those who code in 1's and 0's |
Programm3r
My Blog: ^_^
|
|
|
|
|
So this does the job:
Code = TcpServer.GetData(i, TcpServer.ListenSocket, ref TcpServer.connectData[i].Request, 128);
unsafe static public int GetData(int Connect, int Sock, ref string Buffer, int BufLen)
{
int Code;
fixed (char* pBuffer = Buffer)
{
Code = cscGetData(Sock, pBuffer, BufLen);
if (Code < 0)
{
connectData[Connect].ConnectState = (int)STATE.STATE_FINI;
}
Buffer = Marshal.PtrToStringAnsi((IntPtr)(char*)pBuffer);
}
return Code;
}
Regards,
The only programmers that are better those C# programmers are those who code in 1's and 0's |
Programm3r
My Blog: ^_^
|
|
|
|
|
If you don't want to convert to 'unsafe' code, then the following might do (produced by C++ to C# Converter):
// calling method
private void test()
{
Code = GetData(i, DataSock, ref (string)gConnectData[i].Request, STRING_SIZE);
}
// GetData Method
private int GetData(int Connect, int Sock, ref string Buffer, int BufLen)
{
int Code;
Code = cscGetData(Sock, Buffer, BufLen);
if(Code < 0)
{
DisplayError(Connect, Code, (string)"cscGetData:");
gConnectData[Connect].ConnectState = STATE_FINI;
}
return Code;
}
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
VB & C# to Java Converter
Java to VB & C# Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB, C#, or Java to C++/CLI
|
|
|
|
|
Hello,
Lets say I have a class that exposes event. In which cases do I need to unregister event so that I don't get memory leak? As far as I know if I have a form and I handle form events in the same class there is no need to unregister event myself. But if I attach event handler to form's event then I have to unregister it manually. So, in general when should I unregister event handlers?
Also, if I am developing a class that provides an event and implenets IDisposable, should I unregister attached event handlers in Dispose method?
Thanks.
|
|
|
|
|