|
That's right, the padding is related to strings, if you convert back the string to int, you will lose al format you have applied to it.
|
|
|
|
|
I really like the logic you have used in getting a value with 8 digits, it's great to see people thinking along those lines rather than expecting things to be done with a simple 'out the box' line of code (and thus never really learning how things are actually acheived).
But in instances like this one-liners are the way to go, so hope this helps...
int newNumber = lastReceiptNumber + 1;
string displayNumber = newNumber.ToString("D" + receiptDisplayDigits);
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Thanks man i really appreciate it, we ask question so we could learn how to solve them other wise we are not programers we are just people who ask questions
|
|
|
|
|
Exactly, and questions like yours will always be welcome in The Code Project forums
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Man it worked great but could you explain what is the use with "D" i did not know what did it do.
|
|
|
|
|
some data types (such as int) have the option to overload the ToString method and provide a string containing format information. 'D' followed by a number ensures that the string contains as many preceding zeros as dictated by the number. have a look here[^] for more information
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I am using Relection to get Methods from an Assembly.
I want to display the local Variable names in a method.
I have a test method called Test.
public void Test()
{
string myString = string.Empty;
int myInt = 0;
}
So I am using the following code:
MethodInfo[] methodInfo = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
List<MethodInfo> methods= new List<MethodInfo>(methodInfo);
foreach (MethodInfo method in methods)
{
MethodBody methodBody = method.GetMethodBody();
IList<LocalVariableInfo> localVariables = methodBody.LocalVariables;
}
My problem is, even if I loop through the localVariables collection, I am not able to get the name of the variables of Test Method.
Kindly let me know how do I get the variable names.
Thanks in Advance.
|
|
|
|
|
Hi,
AFAIK local variables are not available in the meta data, except for the method's parameters.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Correct. Reflection only exposes the interface, not the implimentation.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Agreed, I know that,
but I could see the variable names in the method in ildasm so I thought there might be a way to get those. I know ildasm is DISASSEMBLER but took a chance.
Thanks for reply,
Aniruddha
|
|
|
|
|
Hi,
forget Reflector, it won't tell you about locals. You need either the source files or, maybe, the PDB file.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Anir1982 wrote: Kindly let me know how do I get the variable names.
You can't and that is the end of it. It would require that reflection exposes the implimentation of the method rather than the interface.
What use would it be if you could in the long run? You cannot [or should not] be able to change the state of internal variables. Local variables only have scope within the life of a single call to the method. How or when would you be able to constructively use the instance or local variables of a class or method?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
How Can I Select any Row In DataGridVeiw
|
|
|
|
|
example :
dataGridView1.Rows[3].Selected = true;
|
|
|
|
|
Thanks But How Can I MOve The ScrollBar To That Row
|
|
|
|
|
dataGridView1.FirstDisplayedScrollingRowIndex = 3; // set the index of row here..
|
|
|
|
|
I Am Greatfull.
Thanks Again
|
|
|
|
|
Hello!
I have a very simple question. If I want to create an event to my class I can use the EventHandler delegate like this:
public event EventHandler OnLog;
But the EventHandler delegate takes two arguments (the sender and an EventArgs object). If I don't want to have those arguments in my event, is there any other event handler delegate that takes zero arguments or so, or do I have to create the delegate myself?
Regards
|
|
|
|
|
Just use:
if(OnLog != null)
{
OnLog(null, EventArgs.Empty);
}
|
|
|
|
|
or define your own delegate.
or use an Action<type> so you can have exactly one argument with a type you choose.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi all,
I have the following
sda.fill(ds);
string xmlDs = ds.GetXml();
WebRequest req = null;
WebResponse rsp = null;
try
{
string fileName = xmlDs;
string uri = "http://www.website.com/Pages/CongratulationsListener.aspx";
req = WebRequest.Create(uri);
//req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
req.Method = "POST"; // Post method
req.ContentType = "text/xml"; // content type
// Wrap the request stream with a text-based writer
StreamWriter writer = new StreamWriter(req.GetRequestStream());
// Write the XML text into the stream
writer.WriteLine(fileName);
writer.Close();
// Send the data to the webserver
// SendRequest(uri);
rsp = req.GetResponse();
rsp.Close();
}
catch (WebException webEx)
{
}
catch (Exception ex)
{
}
finally
{
if (req != null) req.GetRequestStream().Close();
if (rsp != null) rsp.GetResponseStream().Close();
}
My listner page (CongratulationsListener.aspx) doesnt seem to get any Xml data?
Can any one advice please?
Thank you in advance.
|
|
|
|
|
How I Show System Date And Time In Label
I Perform This task Bt Not Found Actual Result
I USe This Code For Date And Time
Using System.Diagnostics;
Load_Form
DateTime dt = DateTime.Now;
label1.Text = dt.ToShortTimeString();
-------------------------------------
|
|
|
|
|
Bad subject line.
DateTime.Now does gives the system time. What is it giving in your case?
|
|
|
|