|
Hi,
your question isn't very clear. If the variable is an integer, all it takes is if ((var % 100) == x) ... . If the value could be negative, you might need additional code.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
You could try
if(Number.ToString().EndsWith("xx"))
{
}
Although it wont be as efficient as using a mod operator
|
|
|
|
|
Would that even reliably work? I mean:
(quote from MSDN)
The return value is formatted with the general numeric format specifier ("G") and the NumberFormatInfo object for the current culture.
What if under some cultures something other than 0-9 is used, or if they put something at the end, or the middle, or whatever? Do such cultures exist?
I don't know, but using mod sure is a lot safer..
|
|
|
|
|
never convert to string if you don't have to; it is inefficient, creates unnecessary objects, and may be error-prone (e.g. when regional settings may influence it, or when checking for a type match).
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
How would I go about finding the nearest number ending in 'xx' to another number?
|
|
|
|
|
two weeks later, and still at it???
how would you do it manually?
in order to round a positive integer A to a new value B such that B%100=C one must:
1. subtract C from A
2. round to a multiple of 100
3. add C
|
|
|
|
|
Hi,
I've a fair amount of knowledge on collections in C#, but most of the collections that I know of in C# are ordered, indexed or key-enumerated collections. I'm curious to know if there are any special collections that would allows us to have more that 2 fields and the corresponding row values? Please post information regarding this, in case you are aware of.
My requirement states that I have a list having following columns - Year#, Quarter#, QuarterStartDate & QuarterEndDate, with multiple rows under this (as shown below). I need to return the Year & Qtr for any given date.
Year# Quarter# QuarterStartDate QuarterEndDate
----- -------- ---------------- --------------
2010 Qtr1 01-01-2010 31-03-2010
2010 Qtr2 01-04-2010 30-06-2010
..... .... .......... ...........
..... .... .......... ...........
At present, I'm storing this data in a datatable and performing my validations. Is there a collection type in which I can store this data and iterate thru?
Appreciate your time and effort.
Thanks
Arut
|
|
|
|
|
You can use a Dictionary .
One way is to declare a Dictionary<YearQuater, Foo>
YearQuater is a class that defines a year and the quater.
You can also do this:
Dictionary <int, Dictionary <string, Foo >>
in this cast the key on the outer dictionary is the year (I'm assuming int ), the one on the innner is the "Quarter" which I'm assuming is a string
In both my suggestions Foo is the class that contains the row information.
The only collection I've had to hand-roll is a [Formal] "Set" ie a collection with only one instance of an element within it.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
Hi,
since 3.5 .NET offers a HashSet<T>[^]
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
modified on Thursday, February 18, 2010 7:58 AM
|
|
|
|
|
Pants. And I actually looked for it, which is a worry. It's been missing since day one. Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
Hi,
IMO you should turn a row of data into an instance of a user-defined class, then use a generic List of that type.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Hi all,
How can i add a TextBox on a form every time a row in a grid is added.The Gridview refreshes every two minutes for additional row and would like to have a text box next to the Row in a grid to leave a note about the data being added. So for each entry on a grid i would like to have a text box automatically created next to the new row on a gridview.So that i can leave some comments about the data being added on the grid.
Here is the Gridview :
<asp:GridView ID="gvResult" runat="server" AllowPaging="True" CellPadding="4"
Height="16px" Width="45px" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<EmptyDataTemplate>
<asp:Label runat="server">
NO Message List...
</asp:Label>
</EmptyDataTemplate>
<Columns>
<asp:BoundField DataField="CR_CLI" HeaderText="CR_CLI"
SortExpression="CR_CLI" />
How Can I add a text Box that is Just Blank after each Row on a Grid
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:vp2ConnectionString %>"
SelectCommand="SELECT TOP (10) CR_CLI FROM Call WHERE (CR_CLI LIKE '7%') ORDER BY CR_CLI DESC">
</asp:SqlDataSource>
|
|
|
|
|
Post this question in the asp.net forum..45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
|
please help me with sample code for simulating keypress by SendInput. suppose i will pass key press key code like
a,c,num1,function key or key code combination when user press alt+x to another apps by socket communication. then another
apps will press those key. i came to know that sendinput should be use to simulate keypress. so please give me a easy
sample code by which i can implement my logic
thankstbhattacharjee
|
|
|
|
|
Hi,
I've implemented a very simple cache in a winforms-application using a static Colletion of objects. This collection, of course, is initialized at its first use. As the cache does not need to get updated through the whole application lifetime, that's all I need.
My question now is: How to share this static collection through multiple instances of my application? I don't need an extra cache for each instance..
Thanks in adavance.
|
|
|
|
|
Unless your cache is huge or you will be running many instances of your app, I suggest you just load the cache in each process.
If you do need to share your cache, you will have to implement some sort of inter-process communication, which will get messy.
Nick----------------------------------
Be excellent to each other
|
|
|
|
|
I don't think you can, at least not without negating the benfits of the cache. Each instance of the app has its own AppDomain, which has its own allocated memory. (You could achieve this in c++ for example). You 'd need to get a copy of the cache from one application via some sort of RPC or similar, but this would probably be slower than just getting the data again. Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
Thanks for your answers.
What about moving the static collection (cache) to a small library-dll which is referenced from my application. this way, the library-dll would get loaded only one, wouldn't?
|
|
|
|
|
No, the library would load into the AppDomain of each calling application.
This compartmentalisation is so that C# apps can't interfe whith eachother's memory spaces, producing "unexpected" results (e.g. mutex problems, datachanges etc). Objects must be marshalled across app domains, which is a heavy duty task.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
Why do you want to share the cache between multiple instances? The reason I ask is because there may be another way to achieve the required end result (whatever that may be).
As pointed out by others, you might want to share this cache if it is very large and takes up a lot of memory, or if it takes a particularly long time to load up, or if it is changing and needs to be synchronised across all the instances using it.
Otherwise, I suspect that the pain of sharing this cache is going to outweight the benefits. If you decide really do need a shared or distributed cache, it might be worth investigating the caching support in the Enterprise Library Framework, or Spring.NET or similar, to see if they meet your needs.
|
|
|
|
|
My goal is to reduce the application's time of initialisation. Today, every instance creates its own cache, which takes about 30-60 seconds (depending on database's resources). I thought about reducing the time of initialisations to < 5s (for all except the first application's start).
|
|
|
|
|
Obvious, but worth asking:
Have you considered lazy-loading the cache? i.e. only load the info absolutely requied at start up, then loading the rest when they are is accessed for the first time?Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
Yep, lazy-loading was implemented in former version of the application but didn't satisfy the users due to slow runtime performane.
|
|
|
|
|
The hit should only be on the first call per cached element, so I'm surprised at this.
Is it possible to explicitly lazy-load elemtents in the background while the system is idle?Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|