|
Interface and abstract class why we use please explain
|
|
|
|
|
|
Because it is a smart thing to do.
Both allow you to stub out or define aspects of a class that you may know but not completely or you may not be the one ultimately filling in the functionality.
Interfaces allow you to specify what properties, methods, and events MUST be present on an object that conforms to that interface. Take, for example, INotityPropertyChanged. If an object implements that interface, then it MUST expose a PropertyChanged event with a specific signature. When another object wants to be notified that a property changed, it can inspect the target class to see if that interface is implemented and if so, hook the event. Because now you know what the event name and signature must be.
Interfaces, however, only specify the properties, events, and methods that a class must expose and a class may implement more than one interface. Abstract classes, however, have a bit more meat on their bones. They are actual classes but simply stub the method functionality leaving it to be implemented in a class that inherits from the abstract class. A good example might be a data access object that exposes some data stored in the database. You would define an interface for the class including the methods needed to get and save data. You might then create an abstract class that provides some basics but doesn't include any details on how to get to the database. Finally, you might create two or three concrete classes from the abstract class that each know how to connect to a specific database server... maybe one for SQL, another for Oracle, and a 3rd for NoSQL. At runtime you can use reflection to find the proper concrete class and load it. Your code works with only the interfaces but at runtime is provided with the concrete instance of the appropriate class.
HTH!
Jason
|
|
|
|
|
No.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Hi Guys,
Im trying to retrieve a part of a string (a filepath and name) from a field.
However when I do, c# "helpfully" automatically escapes the string.
So instead of the string: C:\folderpath\filename.doc
I end up with: C:\\folderpath\\filename.doc
I've tried using the string.Replace funciton to remove the extra rubbish, but nothing happens.
I've also tried using Regex, but it just complains that it doesnt know what "\f" is.
I've tried adding "@" to the beginning of the string retrieval, but that doesnt help either.
Im running a sql query
using (SqlCommand cmd = new SqlCommand("Select Address1, Address2, LinkedDoc, Recid from Contsupp2 Where Rectype = 'L' AND U_ADDRESS1 Like @param", conn))
{
cmd.Parameters.Add("param", SqlDbType.VarChar,10).Value = @"S:\RWE%";
using (SqlDataReader reader = cmd.ExecuteReader())
{
txt.Clear();
while (reader.Read())
{
string strOrigFilePath = (reader.GetString(2).Substring(reader.GetString(2).IndexOf("FILENAME=") + 9));
Any suggestions as to how I can return a normal string without c# messing it up?
Thanks
|
|
|
|
|
If you're viewing the value in the debugger, it will automatically be shown as an escaped string. The string itself doesn't contain the extra escape characters.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi all,
I am looking for a way to Autofill or auto generate a Bank Transfer form like this
I have a template in word now that i autofill using data i pull from an SQL DB but the problem is that the text in te letter isnt always the same size so or the data on the Transfer is lower or higher so i need another way to add the transfer form at the end of the letter
Is there a DLL available somewhere or a site where i can get info on programming this stuff.
Any help is welcome
kind regards,
Michiel
|
|
|
|
|
when is the "this" refference used when creatinga c#.net application?
|
|
|
|
|
|
What I am trying to do:
I want to add a combobox to the datagridview , with some three items ,like a,b,c, and a last item to be : new, when the user seletcts the last item :new in the combobox , the combobox has to be removed or it should change to textbox allowing to enter a value.
Suggest me whichever is possible ,that should take a value.
|
|
|
|
|
Unlike the ComboBox control, the DataGridViewComboBoxCell does not have SelectedIndex and SelectedValue properties. Instead, selecting a value from a drop-down list sets the cell Value property.
MSDN: The drop-down list values (or the values indicated by the ValueMember property) must include the actual cell values or the DataGridView control will throw an exception. Based on above, I'd rather suggest to manage the items in the combo from a different place than the grid.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for the reply 
|
|
|
|
|
hi , i have error in connection c# with oracle 11g express edition i put my connection string in app.config file "<add name="ConnectionString" connectionString="Provider=MSDAORA;Data Source=localhost;Password=LIB314;User ID=LIB_DB" providerName="System.Data.OleDb" />"
when i want to run a query it gives me error says "The 'MSDAORA' provider is not registered on the local machine" , i use windows 8.1 pro x64 ... any can help me please?
|
|
|
|
|
|
MSDAORA is a 32 bit client. You have two choices really.
1. Compile your application as x86 instead of Any CPU. This forces the application to use 32 bit, so will pick up the DLL.
2. You need to the the full Oracle OleDb[^] client instead.
|
|
|
|
|
thank you for your answer Pete O'Hanlon ... i try the first choice but it does not work for me ... and with the second choice i download the oracle driver but i don't how to use it? can you help me?
|
|
|
|
|
I am doing some exploration ... out of curiosity ... of the 'ExpandoObject in System.Dynamic; so far, I've been able to write a serialize/deserialize to XML function using DataContract, written a method to recursively print to Console all the name/value/Type of the members of a "nested" ExpandoObject.
As you may know, you can add executable code to an ExpandoObject as illustrated in this example:
dynamic TheExpando = new ExpandoObject();
TheExpando.NewProperty = "some new stuff";
TheExpando.NewBagOfProperties = new ExpandoObject();
TheExpando.NewBagOfProperties.DriversLicense = "A873T23L";
TheExpando.NewBagOfProperties.SocialSecurityNumber = "958-349-3988";
TheExpando.SomeInteger = 100;
TheExpando.AnotherInteger = 200;
Action aMethod = new Action(() =>
{
MessageBox.Show((test1.TheExpando.SomeInteger + test1.TheExpando.AnotherInteger).ToString());
test1.TheExpando.SomeInteger += 1000;
});
test1.TheExpando.AMethod = aMethod; And, yes, if you then called TheExpando.AMethod(); you would execute the anonymous method, bring-up a MessageBox, and increment the value of TheExpando.SomeInteger.
Note that I assume the negative hypothesis here: I don't think anonymous methods can be serialized ... not without some kind of very complex code that uses Reflection and yogic contortions. This is a tantalizing post on SO, however: [^].
So far, my research indicates that an Action like 'aMethod in the above code cannot be serialized with DataContract, even though this declaration of 'KnownTypes is legal in setting up a DataContract:
[KnownType(typeof(System.Delegate))]
[KnownType(typeof(System.Action))]
[KnownType(typeof(System.Dynamic.ExpandoObject))]
[DataContract]
public class SomeClassThatIncluesAnExpando
{
[DataMember]
public dynamic TheExpando { set; get; }
} It appears (from my reading on this issue, so far) that you can use a JSON serializer to write an anonymous Type, or Event declaration, to XML.
I have yet to evaluate the 'DataContractResolver facility which might (?) be useful: [^]. I am currently studying this article on serialization of anonymous Types: [^].
I'd appreciate hearing your thoughts on this. Is there any form of Delegate that can be serialized using DataContract ?
fyi: resources
1. ExpandoObject: Use of .NET's Expando object (FrameWork 4.0) in the Dynamic Language Runtime (DLR): [^], [^].
Anoop Madhusudanan has an outstanding article on programming with DLR, using Expando and DynamicObject, and his own very interesting "Elastic Object: [^]; also, see Anoop's blog: [^].
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
modified 7-Mar-14 1:11am.
|
|
|
|
|
BillWoodruff wrote: Note that I assume the negative hypothesis here: I don't think anonymous methods can be serialized Anonymous or not, methods aren't serialized. They're not data.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
A good ... perhaps even definitive ... point to consider, Eddy, but is a Lambda Expression something somewhat other than a method ?
I can certainly store Actions and Funcs in a Dictionary.
thanks, Bill
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
|
|
|
|
|
BillWoodruff wrote: Lambda Expression something somewhat other than a method ? Yes, it's a pointer to a anonymous method.
BillWoodruff wrote: I can certainly store Actions and Funcs in a Dictionary. ..but probably not serialize it, deserialize on a different PC and still have code in there. The pointers would be there, the objects, the count - but not the code. That would have been compiled/optimized to a specific CPU; can you guarantee the same CPU on the target-machine? The correct bitness of the runtime?
You could decompile the code, and compile it again on the target-machine. That'd me somewhat costly, so you might want to keep a copy of the compiled assembly around. The question is rather "what do you want". Depending on that, I'd recommend using an (very generic!) interface, or, perhaps neater, CSharpScript[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy, your replies make perfect "common sense;" I am now wondering how I came to wander so far out on this very shaky nether-limb of the tree of reason
I think this post on SO: [^], coupled with a feverish imagination, led me to an unwarranted generalization of a possible solution for serializing anonymous Types to the idea of serializing anonymous methods.
Both your replies up-voted.
thanks, Bill
“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet
|
|
|
|
|
BillWoodruff wrote: your replies make perfect "common sense;" Happy
BillWoodruff wrote: led me to an unwarranted generalization of a possible solution Key is the word "possible", and yes, nice to see some experimenting and curiosity. Also sounds reasonable to want to serialize code, as one could (e.g.) include the POCO's with the entities. Something like a CSV that contains a type-safe .NET class to handle the data.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
<pre>
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Applica
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo da = new DirectoryInfo("C:\\Folder7");
FileInfo[] Arr = da.GetFiles();
if (Arr.Length == 0)
{
throw new InvalidOperationException("No files found.");
}
FileInfo ap = Arr[Arr.Length - 1];
ulong Totbyte = (ulong)ap.Length;
string filePath = ap.FullName;
string temPath = Path.GetTempFileName();
byte[] data = File.ReadAllBytes(filePath);
File.WriteAllBytes(temPath, data);
byte[] dataa = new byte[1];
for (ulong counter = 0; counter < Totbyte; counter++)
{
dataa[0] = data[counter];
BitArray bits = new BitArray(dataa);
for (int count = 0; count < bits.Length;)
{
if (count != 7)
{
if (bits[count] == false && bits[count + 1] == true)
count++;
if (bits[count] == false && bits[count + 1] == false)
count++;
if (bits[count] == true && bits[count + 1] == true) count++;
if (bits[count] == true && bits[count + 1] == false)
count++;
Console.WriteLine("count = {0}", count);
}
}
}
}
}
}
|
|
|
|
|
When your loop is in its last iteration, count == bits.Length - 1 , so guess what count + 1 is equal to?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|