|
mrithula8 wrote: or2=new Form2();
This shows that you know nothing about object oriented programming. I suggest you buy a book and read it.
And use delegates for your specific problem
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
hi Experts
Pls Tell Me When We Have To Use Abstract Class Or When Interface with Real Life Example
and Program in C#.NET.
I Know The difference But i Not Getting When We Have one of Them.
Dinesh Sharma
|
|
|
|
|
If you want your base type to provide some default functionality out of the box, go for an abstract class. If you want everything to be up to your derived types, go for an interface.
For instance, if I want a Parser type whose descendants will parse files from multiple clients but those file formats have nothing in common, I'd make Parser an interface.
Also bear in mind you can inherit a type from at most one class, abstract or not. Interfaces don't have such restrictions.
|
|
|
|
|
Sharma Dinesh Kumar wrote: When We Have To Use Abstract Class Or When Interface
sorry for my bad English
- use abstract when you want to design code that only in serial derivation objects
- use interface when you want to design code that can be implemented in parallel derivation objects
sample for using abstract object
public abstract class A(){...}
public abstract class B(){...}
class DA : A{...}
class DB : B{...}
you can compare to this sample of using interface
public interface IA{...}
public interface IB{...}
class A : IA{...}
class B : IB{...}
class AB : IA, IB {...}
there are plenty resources from net, try search in Google with keywords "OOP in C#"
hope it helps
dhaim
ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro"
in the front line gave a lead, in the middle line build goodwill, in the behind give power support
|
|
|
|
|
An interface says what properties, methods etc a class must have if it's to implement it but leaves the implementation up to the end class.
An abstract class will provide a default implementation.
You can implement many interfaces in one class, but only one abstract class.
Imagine you wanted to create vehicle classes Car and Bike . One thing they have in common is they have wheels so could have a property WheelCount . Because the number of wheels differs between the two classes it makes no sense to define this in a base class as it'd be wrong for one of them. Better to have an interface that both implement.
public interface IVehicle
{
int WheelCount { get; }
} Let's assume all cars have 4 wheels and all Bikes 2. We could now create base classes where this is hard coded.
public abstract class CarBase
{
public int WheelCount
{
get { return 4; }
}
}
public abstract class BikeBase
{
public int WheelCount
{
get { return 2; }
}
} Cars have doors in varying numbers so lets create an interface for that.
public interface ICar : IVehicle
{
int DoorCount { get; }
} We can now create a Car class like that derives from CarBase and implements ICar and is also IVehicle .
public class Car : CarBase, ICar
{
private int _DoorCount;
public Car(int doorCount)
{
_DoorCount = doorCount;
}
public int DoorCount
{
get { return _DoorCount; }
}
} and for the bike (no further implementation so far)
public class Bike : BikeBase, IVehicle
{ } You can now instanciate these classes treating all Car s as ICar , all Bike s as IBikes , or all vehicles as IVehicle
Car myCar = new Car(4);
Bike myBike = new Bike();
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi all,
I created a Licensed windows forms controls in Internet Explorer,i sell this control to let customer develop web application.
My question is: the licenses file and Dll file is stored under the same folder in server. if the end-user who visit these site. it can download .licenses file and dll file, then they can also create own web application and not purchasing dll. how to limit end-user to use this dll file.
please help me!
the follow url is how to licensed control:
http://windowsclient.net/articles//licensing.aspx
<LINK REL="licenses" HREF="licensedwincontrol.html.licenses">
<OBJECT id = ctrl HEIGHT="200" WIDTH="200"
classid="http:LicensedWinControl.dll#Licensing.LicensedWinControl" >
<PARAM ID="Text" VALUE="Hello from the licensed control">
<PARAM ID="Backcolor" VALUE="Red">
</OBJECT >
|
|
|
|
|
|
how to read data from excel and display it in a list box using visual c# ????
|
|
|
|
|
This is a multi step process. The data in an Excel sheet may or may not be suitable to show in a listbox. Which bit have you tried ? What research have you done ? Where are you stuck ?
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
I am not understanding how to go about it actually !!!
E.g..if i fill 4-5 columns of data in an excel sheet, i want to display them in my form (without any grid view)....[just d values]. I wanted to try with list box, but i guess its not working out for me !!!
can u help me plz...!!
|
|
|
|
|
I won't do all your work for you, no. A listview is surely better than a list box for this ?
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
You can use Ole db to read data from an excel file.
|
|
|
|
|
hw should i display (only the values) in the windows form ??
|
|
|
|
|
Any way you like, really.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
|
How the sequential structure code looked like? Can anyone give me some examples?
Thanks!
|
|
|
|
|
low_sinwei@yahoo.com wrote: How the sequential structure code looked like?
It looked fine. Now tell us what you are asking?
|
|
|
|
|
What are you talking about ?
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Looks like the following:
class Program{public static int Oct(int dec){return ((dec / 8) * 10) + (dec % 8);}static void Main(string[] args){... Anyway I don't encourage you to use it.
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]
|
|
|
|
|
sequential structure code means no function inside right?
thanks for above comments.
|
|
|
|
|
Are you referring to System.Runtime.InteropServices.LayoutKind[^]
Just an example from something I'm currently looking at:
[StructLayout(LayoutKind.Sequential)]
private struct MIDIINCAPS
{
public ushort wMid;
public ushort wPid;
public uint vDriverVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string szPname;
public uint dwSupport;
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6 ? Do you hate yourself ? (Christian Graus)
|
|
|
|
|
I got 5 label side by side and i have a textbox. The textbox value will need to input to the label 1 by 1 after the user click on the button to submit.
Example
protected void btnSave_Click(object sender, EventArgs e)
{
if (label1.text != "") Then
label2.Text = Textbox1.Text;
}
I know the logic for this method is wrong. Any advice?
|
|
|
|
|
Hi,
you could:
1. keep an int that counts the button clicks
2. give the five labels consecutive names (or tags), say label1..label5
3a. inside btnSave_Click() scan myForm.Controls for the Control with the right label# name
3b. alternative: hold an array, say Label[] labels=new Label[5]{label1,label2,...}; and use the counter as an index.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Do you have any sample coding on 3b for me to reference. Thanks.
|
|
|
|
|
It's very simple, why not try to do something yourself before asking someone to give you code ?
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|