|
Hi,
you should check the documentation on operator precedence to find out whether
"Hello"+str==str is the same as "Hello"+(str==str)
or is the same as ("Hello"+str)==str
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Argh, beat me to it!
|
|
|
|
|
|
anishkannan wrote: why did not print "Hello" and why print False instead of True
I guess there's a common reason for...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
For Console.WriteLine(str==str);
here compiler checks "hai" is "hai" or not !!
Compiler : Yes
So your Console.WriteLine(str==str); is "True".
For Console.WriteLine("Hello"+str==str);
now the compiler checks is "Hellohai"(the outcome of "Hello"+str) is "hai".
"Hellohai" == "hai"
Compiler : no
So your Console.WriteLine("Hello"+str==str); is "False".
The key portion here is C# operator Precedence.
|
|
|
|
|
Hi,
I have configured the ASPNET membership database to use for security. I am planning on using Client Application Services with WinForms so that I may be able to have one UserID for the website and the Desktop App.
How can I check the UserId tag in the aspnet_Users table in order to populate a WinForm with information for the specific user?
Currently I have a PersonTable that has a One-To-One relationship with aspnet_users and the Person Table has a One-To-One relationship with the EmployeeTable and a One-To-One relationship with the ClientTable.
Thank you!
Illegal Operation
|
|
|
|
|
Illegal Operation wrote: How can I check the UserId tag in the aspnet_Users table in order to populate a WinForm with information for the specific user?
Are you able to do this from ASP.NET? If yes, best way is to create a web service which will use membership provider APIs. Your windows application can just call this service without messing with ASP.NET APIs.
|
|
|
|
|
What I need to do is reinsert all records exactly as they are from the backup table back into a new table in their corresponding fields.
I am sure there is a better way. The way I would go about doing this is passing a sql reader looping and reinserting the records from 1 table to the other. However this also mess's up the index on the new table.
The new table is structurally different but it has all the same fields as the orgional table, only different order, plus additional fields.
Any good Ideas on what the best way to tackle this? and keep the index's the same?
|
|
|
|
|
JollyMansArt wrote: What I need to do is reinsert all records exactly as they are from the backup table
Ask the question in the correct forum.
only two letters away from being an asset
|
|
|
|
|
debugged a code that calculated savings at 5,10 and 15% for 10, 20, 30, 40 years. The display showed the column heading/information of the percentages whereas the rows held the information for the years. Problem I am having is switching the display to show the years information in the columns and the percentages in the rows. Used a loop to do the first one can't figure out how to change the loop to reflect the other way.
|
|
|
|
|
Could you show some code please? This really isn't enough for me to help you
|
|
|
|
|
This is what was inputted
string employeeName = Console.ReadLine();
Console.Write("Please input your salary: ");
string inputSalary = Console.ReadLine();
double salary = int.Parse(inputSalary);
double balance5Percent = 0.0;
double balance10Percent = 0.0;
double balance15Percent = 0.0;
Console.WriteLine();
Console.WriteLine("{0} at your current salary of {1:C} these are your expected balances", employeeName, salary);
Console.WriteLine();
Console.WriteLine(" 5% 10% 15%");
Console.WriteLine("=========================================================");
for (int i = 1; i <= 40; i++)
{
balance5Percent = (salary * 0.05 + balance5Percent) * 1.08;
balance10Percent = (salary * 0.10 + balance10Percent) * 1.08;
balance15Percent = (salary * 0.15 + balance15Percent) * 1.08;
if (i % 10==0)
{
Console.WriteLine(" Year {0} {1,14:C} {2,14:C} {3,14:C}", i, balance5Percent, balance10Percent, balance15Percent);
}
}
Console.WriteLine("=========================================================");
Console.ReadLine();
}
}
}
|
|
|
|
|
And now instead of 40 lines, you want 40 columns?
That doesn't seem to be especially hard to me - what have you tried?
|
|
|
|
|
No, it is 4 columns instead 3 and now 3 rows with information
|
|
|
|
|
No, the first program was 4 rows with 3 columns now I need 4 columns with 3 rows.
|
|
|
|
|
This[^] may well be what you want.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I see in near every example using threads that the method to execute in the starting of the threads belong to a different class
example: ThreadStart TH = new ThreadStart(Animal1.CuentaAnimales);
Thread Thread1 = new Thread(TH);
And it suggest to me some questions, please tell me if i´m correct or not.
1) Every Thread must include it´s own data an methods so it creates an object for keeping all the code isolates in it´s own space.
2) One Tread cann´t use methods or data created in other Threads.
3) How can I Share one object like a List or Dictionary between different threads.
Best Regards
|
|
|
|
|
1 - no, but if you have multiple threads that all access the same data, make sure you lock it to stop race conditions
2 - not so
3 - just declare it, and access it. Use the lock keyword to make sure each thread waits it's turn.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
About synchronization I see that all the synchronization tools like Lock, Monitor, Mutex need an object like parameter, but I dont know which object I need to introduce for synchronizing a method in the same class in such case I don`t understand to use Lock(this) or Monitor(this), I`m not sinchronizing all the class but only a method.
Thanks
|
|
|
|
|
Most code I've seen does something like
static object synch = new object();
and then just uses that.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
FJJCENTU wrote: I see in near every example using threads that the method to execute in the starting of the threads belong to a different class
Its all personal preferences. I never seen such a code so far though.
1) Not sure what you meant.
2) No. It can use. Make sure you are using proper synchronization mechanisms.
3) Declare it in such a way that it is accessible to both threads. See the following code,
class Foo
{
List<string> strings = new List<string>();
void StartThreads()
{
Thread t1 = new Thread(Thread1Execute);
Thread t2 = new Thread(Thread2Execute);
t1.Start();
t2.Start();
}
void Thread1Execute()
{
}
void Thread2Execute()
{
}
} If your code is doing any modifications to the strings collection, you should use some synchronization mechanisms.
FJJCENTU wrote: in such case I don`t understand to use Lock(this) or Monitor(this), I`m not sinchronizing all the class but only a method.
Using lock(this) is a bad idea. You can choose any object as your locking object. When choosing a locking object, consider the following points.
- The object should not be modifiable without your knowledge. See the following code
class Foo
{
public object locker = new object();
} In this any one can modify the locker object from outside of class Foo without your knowledge. This is dangerous. - All the threads that require this object should be able to access the locker object.
Above class can be written like the below with lock .
class Foo
{
List<string> strings = new List<string>();
readonly object locker = new object();
void StartThreads()
{
Thread t1 = new Thread(Thread1Execute);
Thread t2 = new Thread(Thread2Execute);
t1.Start();
t2.Start();
}
void Thread1Execute()
{
lock(locker)
{
}
}
void Thread2Execute()
{
lock(locker)
{
}
}
} Monitor(this) won't compile. lock is a syntactic sugar which will be compiled as Monitor.Enter and Monitor.Exit .
|
|
|
|
|
Hi,
1) i think Thread can't include it's own data, but process can include the data.
so thread is 'Lightweight'.
2) i think one Thread may create other threads.
(for example, one thread for download file, and a lot of thread created by that thread for download different data in file)
3) you can use public static data to share, but you should remember to synchronous it.
modified 27-May-14 5:34am.
|
|
|
|
|
Hi all,
I have a combo box that can be several values (example: Yes/No/Neither). I want to bind the combobox possible options to a table in a database.
TableOptions
Yes
No
Neither
But lets say a user ran the application and went ahead and selected one of these options. I am storing that selection in a different table.
TableProduct
ProductID Selection
1 No
When the application loads I want it to display the chosen selection (No in this case), but still show the allowable options stored in the first table.
Is this possible?
Thanks
Marc
|
|
|
|
|
Yes. You create the controls to contain the values, then you set each row to the right value, in the item data bound event perhaps ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I am not sure what you mean.
|
|
|
|