|
Thats GR8 To Work LinqPad.
|
|
|
|
|
|
MSDN has some simple tutorials[^], and I can also recommend Charles Petzold's .NET Book Zero[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Just a tip, but I found that many (not all of them) sample code in books where wrong in some way or another. Sometimes it was a type-o, sometimes they use a function that doesn't work or often they have a wrong logic, sometimes you need to have done something else and they forgot to mention. Most problems are small, in a rare occasion it is totally wrong.
I suspect more or less it is done on purpose to let you think and figure out for yourself, but it could be frustrating if you don't expect errors in samples.
V.
|
|
|
|
|
Not sure why this was downvoted, gave it a 4 to compensate.
Textbooks with exercises seem to be out of fashion these days. K&R (the classic C language guide) has them at the end of every chapter, and that was a good idea (even if I didn't actually do most of them!). But it is a good suggestion to read the description of a problem or a language feature, stop before you get to their worked example, and try to solve it/make use of it yourself, then look at what they prepared.
Unfortunately it's so long since I needed non-programmers' introductions that I can't really offer any meaningful advice because my source material is not relevant any more.
|
|
|
|
|
I had a great textbook for learning introductory algorithms like binary searches and stuff like that, and it had exercises at the end of each chapter we read. That helped me learn the material because I was having to create a program based off the exercise that didn't exactly match the samples in the book.
Too bad it's "out of fashion."
|
|
|
|
|
|
I liked Wrox's Beginning Series, the C# one was structured in a way that encouraged you to code while reading.
|
|
|
|
|
|
This article came up in the first search [^]of articles, it should be your first port of call!
Take a look at the guidelines and work out how to ask a question!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I want to display that data from the databse, you can not guide more detailed, the above example we did not understand anything.
I want to display like below:
Date: 21/06/2009----------------------------------------------------------------
name1
name1
name2
Date: 22/06/2009----------------------------------------------------------------
name1
name2
Date: 23/06/2009---------------------------------------------------------------
name3
Thanks
|
|
|
|
|
Hi
I have a WinForm with App.Config file.
There is a <connectionstring> inside the App.Config for MySql server like this:
Server=xxx.xxx.xxx.xxx;Database=xxx;UID=xxx;password=xxx;
Is there any way to extract server value to txtServer, database value to txtDatabase, UID to txtUser and password to txtPassword?
|
|
|
|
|
Not with the built-in tools, but you could write something -- perhaps with a Regular Expression -- or put each in a separate element.
|
|
|
|
|
If it is in the connection strings section you can do ConfigurationManager.ConnectionsStrings[0].Name etc.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
|
Use two splits:
- string[] pieces=connectionString.Split(';');
- each "piece" is a key-value-pair separated by an "=":
string[] pair=piece.Split('=');
|
|
|
|
|
Hi All,
let's suppose
class A
{
int iA1{ get; set; }
int iA2{ get; set; }
}
class B
{
int iB1{ get; set; }
int iB2{ get; set; }
}
class C
{
int iC1{ get; set; }
int iC2{ get; set; }
}
Now i want make type ABC1 for List<<ABC1> and this ABC1 contain iA1,iB1,iC1 and iC2.
But bellow code is not working...plz suggest me, i just want List.
public interface IABC1
{
A a { get; set; }
B b { get; set; }
C c { get; set; }
}
public class ABC1:IABC1
{
#region IABC1 Members
....
...
}
Thanks,
|
|
|
|
|
OK i find it ...just make the public.
class A
{
public int iA1{ get; set; }
public int iA2{ get; set; }
}
Is it better way for multiple inheritance?
Thanks,
|
|
|
|
|
zeeShan anSari wrote: Is it better way for multiple inheritance?
Well, it isn't multiple inheritance, but it may suit your needs better.
And a shameless plug: Implanting Common Code in Unrelated Classes[^]
modified 12-Apr-12 12:40pm.
|
|
|
|
|
C#/.Net doesn't have multiple inheritance. It has multiple implementation (i.e. a class can implement multiple interfaces), so if the things you want to 'inherit' are simple enough, you can implement an interface and re-implement the methods), or alternatively you can switch from 'multiple is-a' (inheritance, which can't be done) to 'multiple has-a' (composition), which is essentially what you've done here.
You can fake multiple inheritance quite well thus:
class Multi {
private A a;
private B b;
Multi(string argForA, int argForB){
a = new A(argForA);
b = new B(argForB);
}
public static implicit operator A(Multi m) { return m.a; }
public static implicit operator B(Multi m) { return m.b; }
}
You can use that class as if it were an A or a B in variable assignments, foreach constructs and anywhere where an implicit cast gets used. However, you can't use a reverse cast (i.e. (Multi)(A)m won't work), the reference you get from a cast isn't actually the same object you started with, and putting it in collections would therefore be dodgy.
I don't really recommend you do that, though.
|
|
|
|
|
I thought about this some more and you can make the fakery even better, as long as you can actually inherit from A and B (which is a requirement for multiple inheritance when it's supported, obviously):
class Multi {
private A a;
private B b;
Multi(string argForA, int argForB){
a = new HostedA(this, argForA);
b = new HostedB(this, argForB);
}
public static implicit operator A(Multi m) { return m.a; }
public static implicit operator B(Multi m) { return m.b; }
public static implicit operator Multi(A a) { return ((HostedA)a).host; }
public static implicit operator Multi(B b) { return ((HostedB)b).host; }
private class HostedA : A {
internal Multi host;
internal HostedA(Multi host, string argsForA) : base(argsForA) {
this.host = host;
}
}
private class HostedB : B {
internal Multi host;
internal HostedB(Multi host, int argsForB) : base(argsForB) {
this.host = host;
}
}
}
Those cast-back operators will fail if you give it the wrong sort of A or B (i.e. one that isn't a cast-out of a Multi), but that's correct (though the exception message might not be quite right). You can override behaviour 'inherited' from A and B in HostedA and HostedB, and as inner classes they have access to their host's private state and methods.
If you want Multi itself to be virtual and inheritable, you can virtualise the creation of the instances of A and B and make the hosted classes visible for inheritance:
class Multi {
private A a;
private B b;
Multi(string argForA, int argForB){
a = ConstructA();
b = ConstructB();
}
protected virtual HostedA ConstructA(string argForA) { return new HostedA(this, argForA); }
protected virtual HostedB ConstructB(int argForB) { return new HostedB(this, argForB); }
public static implicit operator A(Multi m) { return m.a; }
public static implicit operator B(Multi m) { return m.b; }
public static implicit operator Multi(A a) { return ((HostedA)a).Host; }
public static implicit operator Multi(B b) { return ((HostedB)b).Host; }
protected class HostedA : A {
public Multi Host { get; private set; }
public HostedA(Multi host, string argsForA) : base(argsForA) {
this.Host = host;
}
}
protected class HostedB : B {
public Multi Host { get; private set; }
public HostedB(Multi host, int argsForB) : base(argsForB) {
this.Host = host;
}
}
}
To override some of Multi's 'A' behaviour, create a new inner subclass and override the construction method:
class Subclass : Multi {
protected override Multi.HostedA ConstructA(string argForA) { return new HostedA(argForA); }
protected class HostedA : Multi.HostedA {
public HostedA(Multi host, string argsForA) : base(host, argsForA) {}
public override string ToString() { "subclassed A"; }
}
}
... and now ((A)new Subclass("A", 12)).ToString() -> "subclassed A". Casting back with subclassing is a bit ugly though, you can't do (Subclass)(A)mySubclass, instead having to do (Subclass)(Multi)(A)mySubclass.
This retains the disadvantage over real multiple inheritance that a cast from Multi to A gives you a different object (unlike a cast from Button to Control or from an object to an implemented interface). However, the A which is returned maintains a reference to the Multi and protects it from garbage collection, and it should now be castable back (i.e. (Multi)(A)myMulti == (Multi)(B)myMulti == myMulti). And, of course, to use any A methods on a Multi instance you must do ((A)myMulti).MethodOnA(), because the compiler won't know to cast and the methods aren't actually defined on Multi (and although you could create forwarding shims, that makes your code ugly).
However, an approach where you inherit normally from one class and fake-inherit like this from another:
class Multi : A {
private B b;
Multi(string argForA, int argForB) : base(argForA) {
b = ConstructB();
}
protected virtual HostedB ConstructB(int argForB) { return new HostedB(this, argForB); }
public static implicit operator B(Multi m) { return m.b; }
public static implicit operator Multi(B b) { return ((HostedB)b).Host; }
protected class HostedB : B {
public Multi Host { get; private set; }
public HostedB(Multi host, int argsForB) : base(argsForB) {
this.Host = host;
}
}
}
... could make sense if B is a decorator class and A is the main functionality which you want to be able to use normally.
|
|
|
|
|
As noted multiple inheritance isn't possible but you can chain your inheritance
class A
{
int iA1{ get; set; }
int iA2{ get; set; }
}
class B :A
{
int iB1{ get; set; }
int iB2{ get; set; }
}
class C :B
{
int iC1{ get; set; }
int iC2{ get; set; }
}
C c = new C();
c.iA1 = 0;
c.iA2 = 1;
c.iB1 = 2;
c.iB2 = 3;
...
"You get that on the big jobs."
|
|
|
|
|
Hi
I have a desktop C# application that is basically built on Tab control. I have 8 tabs and i need to have different domains to be selected(e.g Admin, clerk, bursar, secretary) on my login where when a user under a specific domain clicks on a certain tab, an event is generated that prevents him from viewing the content of that tab. I was thinking of it this way...
private void Form1_Load(object sender, EventArgs e)
{
if ((Thread.CurrentPrincipal.IsInRole("admin")))
{
tabPage4.Hide();
}
else
{
MessageBox.Show("You must be a member of the Manager or Administrator's roles to view username and password information", "Insufficient Permissions",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
But now instead of
CurrentPrincipal.IsInRole put something that will read the domain name. Something of that sort.
I'll appreciate any help
Thank you
|
|
|
|
|
Why do you make it so complicated, I would manage the visibility based on the users group. If they don't have permission then don't show the tab or disable the tab.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Good Idea.. Thank you, but where do i write the conditional statement?
Just a little illustration please
|
|
|
|