|
If you have a time then you should use TimeSpan.
If you have a timestamp then you should use DateTimeOffset (rather than DateTime.)
|
|
|
|
|
private int m_number;
public int My_NUM
{
get{ return m_number;}
set{m_number=value;}
}
----------
public int M_NUM2
{
get;
set;
}
when we can use of second way why we need to use of first way?
Thanks
|
|
|
|
|
The second way internally creates a version that matches the first, so in this simple case there's no need to do the first one. If your logic needs to do more though, then it becomes important to have the first form. The typical case here is where you have a property that needs to raise a PropertyChanged event when the value changes - you have to trigger this logic from the setter, so you need to do this.
|
|
|
|
|
As Pete already said, the second way is a shorthand for what you have in the first way, however the first way is much more powerful as you can add statements to the get and or the set method, maybe checking an input value and throwing an exception when it is unacceptable; maybe recalculating or repainting something (that is what the TextBox.Text setter would do).
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Second way is property declaration in C# 3.0, for C# 2.0 you have to strict with first implementation.
If you want to do some validation in (get) and (set) then second way should not work. Like, on saving (set) a value you would like to check then you have to write validation code in set block.
private int m_number;
public int My_NUM
{
get{ return m_number;}
set{
if (value > 0)
m_number=value;
}
}
Regards
Rushi
|
|
|
|
|
The second form is also called as Auto Property.
|
|
|
|
|
Hi,
I have a datatable which is having 3 rows ,3 columns (min %,max%,default%)
and the values are string type and values are like 2%,5% etc...
now i want to remove percentage(%) in all the values in the table...ie the column values should be 2,5 etc...
Please help me regarding the same..
-- Modified Wednesday, May 11, 2011 2:19 AM
|
|
|
|
|
It is not clear. Could you clarify this problem?
"The worst code you'll come across is code you wrote last year.", wizardzz[ ^]
|
|
|
|
|
I don't know you what actually you want to accomplish, But to just remove % you can loop through each rows and columns and use following.
table.Rows[i][j].ToString().Replace("%", String.Empty);
Regards,
Hiren.
-"I don't know, I don't care, and it doesn't make any difference".
|
|
|
|
|
Here are two suggestions:
1.
Each column of a DGV has a default style which you can alter; here is a typical statement doing that:
dgvArticles.Columns[DGVA_COL_BOOKMARKS].DefaultCellStyle.Format="#,###";
This would set the style of all data cells in one column, it probably is what you want.
For numbers you can specify different styles for positive, negative and zero values.
2.
Every time a cell is going to be recalculated for later painting, a DGV cell fires its CellFormatting event. You can assign a handler, that determines the style to be used at run-time, and this for individual cells. Here is another (partial) example:
private void dgvUsers_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
if (e.RowIndex...) {
if (e.ColumnIndex...) {
e.CellStyle.BackColor=Color.Gold;
}
}
}
FYI: both examples were inspired by actual code inside my "CP Vanity" article.
BTW: the above is NOT changing the value in the cells, it is only changing the way the cell content looks.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi ,
How can we make sure that which part causes error in MStest failure. ?.Please let me know.
With Thanks regards.
|
|
|
|
|
Could you please be descriptive about the problem.
"The worst code you'll come across is code you wrote last year.", wizardzz[ ^]
|
|
|
|
|
I am working on the code part only.MSTest is written by some1 else.When I run the MStest after making changes to few files in a project , it is getting failed.I just want to know which change in which file triggering the error in MStest.Any idea ?
|
|
|
|
|
You will have to look at the test case which is failing and see which method it is testing. The error should be a clue.
"The worst code you'll come across is code you wrote last year.", wizardzz[ ^]
|
|
|
|
|
Show code and message.
More help would come.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Hi all,
In my system in a service is running at the backend.I want to use that service in my windows application how can i do it ?
An exe file for that service also i am having. But how can i use that service in my application.
Thanks in advance.
|
|
|
|
|
Is it a windows service? Or a web service?
"The worst code you'll come across is code you wrote last year.", wizardzz[ ^]
|
|
|
|
|
Its a windows service which is already running, but i am not having any svc or any other file.Only exe file of that service is available.
|
|
|
|
|
What do you mean by "using" it? If you want to start or stop the service, you can use ServiceController class.
If you need to call a method from the service, you should not be using the service at all. If it has class library collection for the business layer and data access etc, use them as reference in your application.
"The worst code you'll come across is code you wrote last year.", wizardzz[ ^]
|
|
|
|
|
You have not mentioned, How you want to use that service?
SVC file is only required to register a service as a windows service, so a simple .EXE file can be register as windows services.
You can directly use that Exe file and execute it using Shell command.
Regards
Rushi
|
|
|
|
|
hi,
I have used the below code on datagridview1_ColumnHeaderMouseClick
foreach (DataGridViewColumn x in datagridview1.Columns)
{
x.SortMode = DataGridViewColumnSortMode.Automatic;
x.Selected = true;
}
sorting is not happening ...
even i have tried...
private int Order=-1;
the below code is inside datagridview1_ColumnHeaderMouseClick
Collapse | Copy Code
ListSortDirection sortDirection;
if (this.datagridview1.SortedColumn.Name == "Number")
{
if (this.Order == -1)
{
sortDirection = ListSortDirection.Descending;
datagridview1.Sort(datagridview1.Columns["Number"], sortDirection);
datagridview1.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.Descending;
this.Order = 1;
}
else
{
sortDirection = ListSortDirection.Ascending;
datagridview1.Sort(datagridview1.Columns["Number"], sortDirection);
datagridview1.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.Ascending;
this.Order = -1;
}
}
even the above code is not working....
please help me regarding the same....
|
|
|
|
|
Hi,
a DGV is a complex Control. I got it sorting any way I want, see e.g. my "CP Vanity" article.
From memory, and maybe not 100% accurate:
1. It would not sort (but throw some exception) when databound to something that does not implement IBindingList; that is why I often use a DataTable, not just a List as a data source.
2. It would sort in the natural way when set to Automatic, without requiring any extra code.
3. It could be made to sort in odd ways by setting to Programmatic and calling Sort() explicitly, again see CP Vanity.
Note: I would never change the sort mode inside a click handler, in fact I think the sort mode for each column typically should be constant throughout the app's life, it may be different amongst columns, but I see no need to change it over time.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Tuesday, May 10, 2011 11:31 PM
|
|
|
|
|
Hi, how can i get the real html code in a webbrowser object??? a mean, if the page has the following code:
Document.write("Text");
i wanna get the code after the js runs. what i want is to get this:
Text
thanks,
Marcus.
|
|
|
|
|
I'm not sure, however I would try this:
- make sure your Internet Explorer has JavaScript enabled;
- use a WebBrowser;
- have it Navigate(string) to the URL you want;
- use it's DocumentCompleted event to obtain its Document property.
Caveat: complex pages may fire their DocumentCompleted event many times; what I typically do is compare the current WebBrowserDocumentCompletedEventArgs.URL with the original one, until they match.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks, but webbrowser1.DocumentText doesnt work, it gets:
<html>
<body>
Document.write("Text");
</body>
</html>
=/ i dont know what to do anymore.
|
|
|
|