|
Hello how i can daclare a public ArrayList? i declare: ArrayList Tbl = new ArrayList();, but there are an error : Error 1 The name 'tbl' does not exist in the current context D:\PROJETS\test.cs 79 49 test
Thank you verry mutch.
|
|
|
|
|
|
I hate case sensitive languages, coming from a VB background this has the potential to trip me up every time.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
the problem is like the folowing---
SEND
+ MORE
-----------
MONEY
i hav to solve this prob lem ..
if any one can help me ...plz..
i will be very much grateful to...him/her.
if code segment is attached then it willbw excelent.
i hav to submit the solution tomorrow....
plz help me!!!!
thanx in advance.
TANIM
TAFIN
cse 2003
ShahJalal University
|
|
|
|
|
1. Why on C# forums?
2. Why not on algorithms forums?
3. Why that looks like homework / contest?
4. What's the problem?
|
|
|
|
|
You do realise you are feeding a troll right!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
We have few troll slayers on CodeProject so I wouldn't panic .
|
|
|
|
|
Hey, I am trying to write get/set properties for an array
public class MyClass
{
private MyType[] MyArray = new MyType[10];
public MyType this[int index]
get
{
return MyArray[index];
}
set
{
MyArray[index] = value;
}
}
but when I use code like this
MyClass instance = new MyClass();
instance[index].MyProperty = " ";
I get a NullReferenceException, can anyone tell me what is wrong with this code?
Thankyou
|
|
|
|
|
Maybe constructor of your class (MyClass) is not filling array with "MyType" (which is a class)? So instance[index].MyProperty == null , and you are referencing to it.
|
|
|
|
|
Yes, "MyType" is a class.
In the constructor I have MyArray = new MyType[arraySize] is that what you mean by "filling the array"?
|
|
|
|
|
You create array of references, without creating objects, so what you get is array full of null references. Then you are refering to one of this object, which generates NullRefException.
|
|
|
|
|
If that is all, then MyArray will just contain 10 nulls.
|
|
|
|
|
Yes, it makes sense now.
Thankyou
|
|
|
|
|
I'm trying to obtain the path of the file(s) that o certain process reads from or writes to (similar to the way Performance Monitor does in Vista).
I couldn't find out any direct method neither using WMI (Win32_Process class), nor the Process class from
System.Diagnostics.
Thank you.
|
|
|
|
|
|
Thanks for the reply, Giorgi.
I've managed to find a way to obtain file handles for a process. Here is the code:
[DllImport("ntdll.dll", SetLastError = true)]
public static extern uint ZwQuerySystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, IntPtr SystemInformation, int SystemInformationLength, out int ReturnLength);
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_HANDLE_INFORMATION
{
public int ProcessId;
public byte ObjectTypeNumber;
public byte Flags;
public short Handle;
public int Object;
public int GrantedAccess;
}
public const uint STATUS_INFO_LENGTH_MISMATCH = 0xc0000004;
public static SYSTEM_HANDLE_INFORMATION[] EnumHandles()
{
int retLength = 0;
int handleCount = 0;
SYSTEM_HANDLE_INFORMATION[] returnHandles;
int allocLength = 0x1000;
IntPtr data = Marshal.AllocHGlobal(allocLength);
while (ZwQuerySystemInformation(SYSTEM_INFORMATION_CLASS.SystemHandleInformation, data,
allocLength, out retLength) == STATUS_INFO_LENGTH_MISMATCH)
{
data = Marshal.ReAllocHGlobal(data, new IntPtr(allocLength *= 2));
}
handleCount = Marshal.ReadInt32(data);
returnHandles = new SYSTEM_HANDLE_INFORMATION[handleCount];
for (int i = 0; i < handleCount; i++)
{
returnHandles[i] = (SYSTEM_HANDLE_INFORMATION)Marshal.PtrToStructure(
new IntPtr(data.ToInt32() + 4 + i * Marshal.SizeOf(typeof(SYSTEM_HANDLE_INFORMATION))),
typeof(SYSTEM_HANDLE_INFORMATION));
}
Marshal.FreeHGlobal(data);
return returnHandles;
}
Then I'd like to obtain the handles for a specific process:
SYSTEM_HANDLE_INFORMATION[] handles = EnumHandles();
var winampHandles = from handle in handles
where handle.ProcessId == 10004
select handle;
foreach (var winampHandle in winampHandles)
{
}
As we can see, each handle is an object of type SYSTEM_HANDLE_INFORMATION, which does not contain a field specifying the name of the handle. To obtain the name of the handle (e.g. the file path), I think I need to call some Win API.
MSDN has an example of how to to this: http://msdn.microsoft.com/en-us/library/aa366789(VS.85).aspx[^], but it is written in C, and I need it for C#.
Is there some other way around this thing? I've tryed using the FileStream class, and pass to it's ctor the handle:
FileStream fs = new FileStream(new IntPtr(winampHandle.Handle), FileAccess.ReadWrite, false); , which throws an IO Exception ("Invalid handle"). Passing a SafeFileHandle to the ctor didn't solve the problem.
Any ideas?
|
|
|
|
|
Hi, I am sorry for some earlier posts as i was bit confused on my design of application...
Ok..I have BillDetails,Products,Packing Table...
And on winform I have gridview...Now in gridview I want to display billdetails table..but somehow the first two columns need to be combobox..and these combobox should take data from Products Table together with Packing..
I have screen shot as what exist in those tables..Also below is a small code that i have done but i see only one dropdown list with nothing populated...
Please HELP..I will really appreciate as i am stuck in it for few days
:confused:void fillData()
{
OleDbConnection database = new OleDbConnection(connectionString);
database.Open();
OleDbDataAdapter adapter1 = new OleDbDataAdapter("SELECT BillDetails.ProductID, BillDetails.ProductName, BillDetails.InQty, BillDetails.InBns, BillDetails.InPrice, BillDetails.Dis1, Products.packing, BillDetails.Saletype, BillDetails.SBtype, Products.FactorC, Products.FactorB, BillDetails.Type FROM Products INNER JOIN BillDetails ON Products.ProdID = BillDetails.ProductID", database);
DataGridViewComboBoxColumn dgridcolumn = new DataGridViewComboBoxColumn();
dgridcolumn.Name = "Products";
this.dataGridView1.Columns.Add(dgridcolumn);
DataTable dt = new DataTable();
DataTable packDT = new DataTable();
adapter1.Fill(dt);
dataGridView1.DataSource = dt;
adapter1.Fill(packDT);
dgridcolumn.DataSource = packDT;
dgridcolumn.ValueMember = packDT.Columns[1].ColumnName.ToString();
dgridcolumn.DisplayMember = packDT.Columns[1].ColumnName.ToString();
}
|
|
|
|
|
Hello everyone,
I am stuck with the following problem.
I have given text "We are living in a <upcase>yellow submarine</upcase>.", I have to change the text inside <upcase>....</upcase> to a uppercase letters so the result will be
"We are living in a YELLOW SUBMARINE."
Ill appreciate any help and suggestions how this can be done.
Thanks in advance!!
Regards
Georgi Uzunov
modified on Saturday, March 21, 2009 10:08 AM
|
|
|
|
|
How do you know which part should be in upper case? If it's always the same text you might as well just output the right output..
|
|
|
|
|
My fault the text should be "We are living in a <upcase>yellow submarine</upcase>.
So I have to replace upcase ...... /upcase with the uppercase text.
Apologies.
|
|
|
|
|
Try this.
string openTag = "<upcase>", closeTag = "</upcase>";
string str = "We are living in a <upcase>yellow submarine</upcase>.";
int startIndex = str.IndexOf(openTag);
int endIndex = str.IndexOf(closeTag) + closeTag.Length;
string subStr = str.Substring(startIndex, (endIndex - startIndex));
subStr = subStr.Replace(openTag, "");
subStr = subStr.Replace(closeTag, "");
subStr = subStr.ToUpper();
str = str.Remove(startIndex, (endIndex - startIndex));
str = str.Insert(startIndex, subStr);
hmmm pie
|
|
|
|
|
Thank you very much sir. It work like a charm Now I have to see how to put this in a loop so I can check bigger strings with more tags.
One more time Thanks.
Greetings!
|
|
|
|
|
Funny you should mention that as I was going to edit thte above code for multiple tags.
private string upperCaseTags(string str, string openTag, string closeTag)
{
int startIndex;
while ((startIndex = str.IndexOf(openTag)) != -1)
{
int endIndex;
if ((endIndex = str.IndexOf(closeTag) + closeTag.Length) != -1)
{
string subStr = str.Substring(startIndex, (endIndex - startIndex));
subStr = subStr.Replace(openTag, "").Replace(closeTag, "").ToUpper();
str = str.Remove(startIndex, (endIndex - startIndex));
str = str.Insert(startIndex, subStr);
}
}
return str;
}
hmmm pie
|
|
|
|
|
One more time great job. You did it instead of me.
Thank you!
|
|
|
|
|
This can be improved by Regular Expression's Replace[^] method.
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|