Search Results

Search found 2457 results on 99 pages for 'implicit cast'.

Page 11/99 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • Performance: float to int cast and clippling result to range

    - by durandai
    I'm doing some audio processing with float. The result needs to be converted back to PCM samples, and I noticed that the cast from float to int is surprisingly expensive. Whats furthermore frustrating that I need to clip the result to the range of a short (-32768 to 32767). While I would normally instictively assume that this could be assured by simply casting float to short, this fails miserably in Java, since on the bytecode level it results in F2I followed by I2S. So instead of a simple: int sample = (short) flotVal; I needed to resort to this ugly sequence: int sample = (int) floatVal; if (sample > 32767) { sample = 32767; } else if (sample < -32768) { sample = -32768; } Is there a faster way to do this? (about ~6% of the total runtime seems to be spent on casting, while 6% seem to be not that much at first glance, its astounding when I consider that the processing part involves a good chunk of matrix multiplications and IDCT)

    Read the article

  • Cast enum to integer

    - by Shanish
    I have a enum class called Gender and I have values in this like public enum GENDER { MALE = 1, FAMALE = 2, OTHERS = 3, } and in my business object I just created a property for this like public GENDER Gender { get { return gender; } set { gender = value; } } in my database its in type integer. For this I tried to assign the Gender value in the add function by its name Gender. but its showing error. Is it possible to cast the enum to integer so that it'll get the value automatically. can anyone help me out here....

    Read the article

  • fetchedResultsController objectAtIndexPath: i "Passing argument 1 of objectAtIndexPath: makes pointer from integer without cast

    - by cocos2dbeginner
    NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:0]; for (int i; i<[sectionInfo numberOfObjects]; i++) { NSManagedObject *o = [self.fetchedResultsController objectAtIndexPath:i]; [dict setObject:[[o valueForKey:@"frontCard"] description] forKey:@"frontCard"]; [dict setObject:[[o valueForKey:@"flipCard"] description] forKey:@"flipCard"]; } In this line NSManagedObject *o = [self.fetchedResultsController objectAtIndexPath:i]; i get this warning: warning: passing argument 1 of 'objectAtIndexPath:' makes pointer from integer without a cast

    Read the article

  • scala implicit or explicit conversion from iterator to iterable

    - by landon9720
    Does Scala provide a built-in class, utility, syntax, or other mechanism for converting (by wrapping) an Iterator with an Iterable? For example, I have an Iterator[Foo] and I need an Iterable[Foo], so currently I am: val foo1: Iterator[Foo] = .... val foo2: Iterable[Foo] = new Iterable[Foo] { def elements = foo1 } This seems ugly and unnecessary. What's a better way?

    Read the article

  • Void pointer cast C++ and GTK

    - by Tarantula
    See this GTK callback function: static gboolean callback(GtkWidget *widget, GdkEventButton *event, gpointer *data) { AnyClass *obj = (AnyClass*) data; // using obj works } (please note the gpointer* on the data). And then the signal is connected using: AnyClass *obj2 = new AnyClass(); gtk_signal_connect(/*GTK params (...)*/, callback, obj2); See that the *AnyClass is going to be cast to gpointer* (void**). In fact, this is working now. The callback prototype in GTK documentation is "gpointer data" and not "gpointer *data" as shown in code, what I want to know is: how this can work ? Is this safe ?

    Read the article

  • Easy way to cast an object array into another type in C#

    - by Na7coldwater
    I want to be able to be able to quickly cast an array of objects to a different type, such as String, but the following code doesn't work: String[] a = new String[2]; a[0] = "Hello"; a[1] = "World"; ArrayList b = new ArrayList(a); String[] c = (String[]) b.ToArray(); And I don't want to have to do this: String[] a = new String[2]; a[0] = "Hello"; a[1] = "World"; ArrayList b = new ArrayList(a); Object[] temp = b.ToArray(); Object[] temp = b.ToArray(); String[] c = new String[temp.Length]; for(int i=0;i<temp.Length;i++) { c[i] = (String) temp[i]; } Is there an easy way to do this without using a temporary variable?

    Read the article

  • Cast Graphics to Image in C#

    - by WebDevHobo
    I have a pictureBox on a Windows Form. I do the following to load a PNG file into it. Bitmap bm = (Bitmap)Image.FromFile("Image.PNG", true); Bitmap tmp; public Form1() { InitializeComponent(); this.tmp = new Bitmap(bm.Width, bm.Height); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawImage(this.bm, new Rectangle(0, 0, tmp.Width, tmp.Height), 0, 0, tmp.Width, tmp.Height, GraphicsUnit.Pixel); } However, I need to draw things on the image and then have the result displayed again. Drawing rectangles can only be done via the Graphics class. I'd need to draw the needed rectangles on the image, make it an instance of the Image class again and save that to this.bm I can add a button that executes this.pictureBox1.Refresh();, forcing the pictureBox to be painted again, but I can't cast Graphics to Image. Because of that, I can't save the edits to the this.bm bitmap. That's my problem, and I see no way out.

    Read the article

  • java.lang.ClassCastException: $Proxy99 cannot be cast

    - by svaret
    Hi, I am using JBoss4.2.2 and java6. The deployed ear's name is apa.ear In a servlet I have the following code line: placeBid = (PlaceBid) context.lookup("apa/" + PlaceBid.class.getSimpleName() + "/remote"); I have a generated jboss-app.xml like this: <jboss-app> <loader-repository>apa:app=ejb3</loader-repository> </jboss-app> When trying to get the PlaceBid via the context I get this exception java.lang.ClassCastException: $Proxy99 cannot be cast to se.nextit.actionbazaar.buslogic.PlaceBid The PlaceBid interface looks like this: @Remote public interface PlaceBid { Long addBid(String userId, Long itemId, Double bidPrice); } When I run the example coming with EJB3 in action it works. EJB3 in action sample code comes with ant building. I want to use Maven so I have rearranged the code some. However, I don't understan what I am doing wrong here. I have some thoughts about the jboss-app.xml file. I am not sure of how its content should look like. Grateful for any help. Best wishes Lasse

    Read the article

  • VB.NET invalid cast exception

    - by user127147
    Hi there, I have a simple application to store address details and edit them. I have been away from VB for a few years now and need to refreash my knowledge while working to a tight deadline. I have a general Sub responsible for displaying a form where user can add contact details (by pressing button add) and edit them (by pressing button edit). This sub is stored in a class Contact. The way it is supposed to work is that there is a list with all the contacts and when new contact is added a new entry is displayed. If user wants to edit given entry he or she selects it and presses edit button Public Sub Display() Dim C As New Contact C.Cont = InputBox("Enter a title for this contact.") C.Fname = frmAddCont.txtFName.Text C.Surname = frmAddCont.txtSName.Text C.Address = frmAddCont.txtAddress.Text frmStart.lstContact.Items.Add(C.Cont.ToString) End Sub I call it from the form responsible for adding new contacts by Dim C As New Contact C.Display() and it works just fine. However when I try to do something similar using the edit button I get errors - "Unable to cast object of type 'System.String' to type 'AddressBook.Contact'." Dim C As Contact If lstContact.SelectedItem IsNot Nothing Then C = lstContact.SelectedItem() C.Display() End If I think it may be something simple however I wasn't able to fix it and given short time I have I decided to ask for help here. Thank you

    Read the article

  • Cast errors with IXmlSerializable

    - by Nathan
    I am trying to use the IXmlSerializable interface to deserialize an Object (I am using it because I need specific control over what gets deserialized and what does not. See my previous question for more information). However, I'm stumped as to the error message I get. Below is the error message I get (I have changed some names for clarity): An unhandled exception of type 'System.InvalidCastException' occurred in App.exe Additional information: Unable to cast object of type 'System.Xml.XmlNode[]' to type 'MyObject'. MyObject has all the correct methods defined for the interface, and regardless of what I put in the method body for ReadXml() I still get this error. It doesn't matter if it has my implementation code or if it's just blank. I did some googling and found an error that looks similar to this involving polymorphic objects that implement IXmlSerializable. However, my class does not inherit from any others (besides Object). I suspected this may be an issue because I never reference XmlNode any other time in my code. Microsoft describes a solution to the polymorphism error: https://connect.microsoft.com/VisualStudio/feedback/details/422577/incorrect-deserialization-of-polymorphic-type-that-implements-ixmlserializable?wa=wsignin1.0#details The code the error occurs at is as follows. The object to be read back in is an ArrayList of "MyObjects" IO::FileStream ^fs = gcnew IO::FileStream(filename, IO::FileMode::Open); array<System::Type^>^ extraTypes = gcnew array<System::Type^>(1); extraTypes[0] = MyObject::typeid; XmlSerializer ^xmlser = gcnew XmlSerializer(ArrayList::typeid, extraTypes); System::Object ^obj; obj = xmlser->Deserialize(fs); fs->Close(); ArrayList ^al = safe_cast<ArrayList^>(obj); MyObject ^objs; for each(objs in al) //Error occurs here { //do some processing } Thanks for reading and for any help.

    Read the article

  • warning: assignment makes pointer from integer without a cast

    - by FILIaS
    Im new in programming c with arrays and files. Im just trying to run the following code but i get warnings like that: warning: assignment makes pointer from integer without a cast Any help? It might be silly... but I cant find what's wrong. FILE *fp; FILE *cw; char filename_game[40],filename_words[40]; int main() { while(1) { /* Input filenames. */ printf("\n Enter the name of the file with the cryptwords array: \n"); gets(filename_game); printf("\n Give the name of the file with crypted words:\n"); gets(filename_words); /* Try to open the file with the game */ if (fp=fopen("crypt.txt","r")!=NULL) { printf("\n Successful opening %s \n",filename_game); fclose(fp); puts("\n Enter x to exit,any other to continue! \n "); if ( (getc(stdin))=='x') break; else continue; } else { fprintf(stderr,"ERROR!%s \n",filename_game); puts("\n Enter x to exit,any other to continue! \n"); if (getc(stdin)=='x') break; else continue; } /* Try to open the file with the names. */ if (cw=fopen("words.txt","r")!=NULL) { printf("\n Successful opening %s \n",filename_words); fclose(cw); puts("\n Enter x to exit,any other to continue \n "); if ( (getc(stdin))=='x') break; else continue; } else { fprintf(stderr,"ERROR!%s \n",filename_words); puts("\n Enter x to exit,any other to continue! \n"); if (getc(stdin)=='x') break; else continue; } } return 0; }

    Read the article

  • How do I DYNAMICALLY cast in C# and return for a property

    - by ken-forslund
    I've already read threads on the topic, but can't find a solution that fits. I'm working on a drop-down list that takes an enum and uses that to populate itself. i found a VB.NET one. During the porting process, I discovered that it uses DirectCast() to set the type as it returns the SelectedValue. See the original VB here: http://jeffhandley.com/archive/2008/01/27/enum-list-dropdown-control.aspx the gist is, the control has Type _enumType; //gets set when the datasource is set and is the type of the specific enum The SelectedValue property kind of looks like (remember, it doesn't work): public Enum SelectedValue //Shadows Property { get { // Get the value from the request to allow for disabled viewstate string RequestValue = this.Page.Request.Params[this.UniqueID]; return Enum.Parse(_enumType, RequestValue, true) as _enumType; } set { base.SelectedValue = value.ToString(); } } Now this touches on a core point that I think was missed in the other discussions. In darn near every example, folks argued that DirectCast wasn't needed, because in every example, they statically defined the type. That's not the case here. As the programmer of the control, I don't know the type. Therefore, I can't cast it. Additionally, the following examples of lines won't compile because c# casting doesn't accept a variable. Whereas VB's CType and DirectCast can accept Type T as a function parameter: return Enum.Parse(_enumType, RequestValue, true); or return Enum.Parse(_enumType, RequestValue, true) as _enumType; or return (_enumType)Enum.Parse(_enumType, RequestValue, true) ; or return Convert.ChangeType(Enum.Parse(_enumType, RequestValue, true), _enumType); or return CastTo<_enumType>(Enum.Parse(_enumType, RequestValue, true)); So, any ideas on a solution? What's the .NET 3.5 best way to resolve this?

    Read the article

  • JPA native query join returns object but dereference throws class cast exception

    - by masato-san
    I'm using JPQL Native query to join table and query result is stored in List<Object[]>. public String getJoinJpqlNativeQuery() { String final SQL_JOIN = "SELECT v1.bitbit, v1.numnum, v1.someTime, t1.username, t1.anotherNum FROM MasatosanTest t1 JOIN MasatoView v1 ON v1.username = t1.username;" System.out.println("get join jpql native query is being called ============================"); EntityManager em = null; List<Object[]> out = null; try { em = EmProvider.getDefaultManager(); Query query = em.createNativeQuery(SQL_JOIN); out = query.getResultList(); System.out.println("return object ==========>" + out); System.out.println(out.get(0)); String one = out.get(0).toString(); //LINE 77 where ClassCastException System.out.println(one); } catch(Exception e) { } finally { if(em != null) { em.close; } } } The problem is System.out.println("return object ==========>" + out); outputs: return object ==========> [[true, 0, 2010-12-21 15:32:53.0, masatosan, 0.020], [false, 0, 2010-12-21 15:32:53.0, koga, 0.213]] System.out.println(out.get(0)) outputs: [true, 0, 2010-12-21 15:32:53.0, masatosan, 0.020] So I assumed that I can assign return value of out.get(0) which should be String: String one = out.get(0).toString(); But I get weird ClassCastException. java.lang.ClassCastException: java.util.Vector cannot be cast to [Ljava.lang.Object; at local.test.jaxrs.MasatosanTestResource.getJoinJpqlNativeQuery (MasatosanTestResource.java:77) So what's really going on? Even Object[] foo = out.get(0); would throw an ClassCastException :(

    Read the article

  • Cant' cast a class with multiple inheritance

    - by Jay S.
    I am trying to refactor some code while leaving existing functionality in tact. I'm having trouble casting a pointer to an object into a base interface and then getting the derived class out later. The program uses a factory object to create instances of these objects in certain cases. Here are some examples of the classes I'm working with. // This is the one I'm working with now that is causing all the trouble. // Some, but not all methods in NewAbstract and OldAbstract overlap, so I // used virtual inheritance. class MyObject : virtual public NewAbstract, virtual public OldAbstract { ... } // This is what it looked like before class MyObject : public OldAbstract { ... } // This is an example of most other classes that use the base interface class NormalObject : public ISerializable // The two abstract classes. They inherit from the same object. class NewAbstract : public ISerializable { ... } class OldAbstract : public ISerializable { ... } // A factory object used to create instances of ISerializable objects. template<class T> class Factory { public: ... virtual ISerializable* createObject() const { return static_cast<ISerializable*>(new T()); // current factory code } ... } This question has good information on what the different types of casting do, but it's not helping me figure out this situation. Using static_cast and regular casting give me error C2594: 'static_cast': ambiguous conversions from 'MyObject *' to 'ISerializable *'. Using dynamic_cast causes createObject() to return NULL. The NormalObject style classes and the old version of MyObject work with the existing static_cast in the factory. Is there a way to make this cast work? It seems like it should be possible.

    Read the article

  • Dynamically cast a control type in runtime

    - by JayT
    Hello, I have an application whereby I dynamically create controls on a form from a database. This works well, but my problem is the following: private Type activeControlType; private void addControl(ContainerControl inputControl, string ControlName, string Namespace, string ControlDisplayText, DataRow drow, string cntrlName) { Assembly assem; Type myType = Type.GetType(ControlName + ", " + Namespace); assem = Assembly.GetAssembly(myType); Type controlType = assem.GetType(ControlName); object obj = Activator.CreateInstance(controlType); Control tb = (Control)obj; tb.Click += new EventHandler(Cntrl_Click); inputControl.Controls.Add(tb); activeControlType = controlType; } private void Cntrl_Click(object sender, EventArgs e) { string test = ((activeControlType)sender).Text; //Problem ??? } How do I dynamically cast the sender object to a class that I can reference the property fields of it. I have googled, and found myself trying everything I have come across..... Now I am extremely confused... and in need of some help Thnx JT

    Read the article

  • Weird exception: Cannot cast String to Boolean when using getBoolean

    - by La bla bla
    I'm getting a very weird error. I have 2 activities. On both I'm getting the SharedPreferences using MODE_PRIVATE (if it matters) by sp = getPreferences(MODE_PRIVATE); on each activity's onCreate() I'm calling sp.getBoolean(IntroActivity.SHOW_INTRO, true) On the IntroActivity this works fine. But when I'm trying in the main activity, I'm getting this 10-12 04:55:23.208: E/AndroidRuntime(11668): FATAL EXCEPTION: main 10-12 04:55:23.208: E/AndroidRuntime(11668): java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean 10-12 04:55:23.208: E/AndroidRuntime(11668): at android.app.SharedPreferencesImpl.getBoolean(SharedPreferencesImpl.java:242) 10-12 04:55:23.208: E/AndroidRuntime(11668): at com.lablabla.parkme.ParkMeActivity$2.onClick(ParkMeActivity.java:194) 10-12 04:55:23.208: E/AndroidRuntime(11668): at android.view.View.performClick(View.java:4084) 10-12 04:55:23.208: E/AndroidRuntime(11668): at android.view.View$PerformClick.run(View.java:16966) 10-12 04:55:23.208: E/AndroidRuntime(11668): at android.os.Handler.handleCallback(Handler.java:615) 10-12 04:55:23.208: E/AndroidRuntime(11668): at android.os.Handler.dispatchMessage(Handler.java:92) 10-12 04:55:23.208: E/AndroidRuntime(11668): at android.os.Looper.loop(Looper.java:137) 10-12 04:55:23.208: E/AndroidRuntime(11668): at android.app.ActivityThread.main(ActivityThread.java:4745) 10-12 04:55:23.208: E/AndroidRuntime(11668): at java.lang.reflect.Method.invokeNative(Native Method) 10-12 04:55:23.208: E/AndroidRuntime(11668): at java.lang.reflect.Method.invoke(Method.java:511) 10-12 04:55:23.208: E/AndroidRuntime(11668): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 10-12 04:55:23.208: E/AndroidRuntime(11668): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 10-12 04:55:23.208: E/AndroidRuntime(11668): at dalvik.system.NativeStart.main(Native Method) I made sure that I'm not putting a String somewhere in the middle with that same key Any ideas? Thanks! EDIT: some code: //onCreate() sp = getPreferences(MODE_PRIVATE); // other method boolean showIntro = sp.getBoolean(IntroActivity.SHOW_INTRO, true); // Exception is here showIntroCheckBox.setChecked(showIntro); If it matters, the code which throws the exception is inside a button's onClick

    Read the article

  • Query Parameter Value Is Null When Enum Item 0 is Cast with Int32

    - by Timothy
    When I use the first item in a zero-based Enum cast to Int32 as a query parameter, the parameter value is null. I've worked around it by simply setting the first item to a value of 1, but I was wondering though what's really going on here? This one has me scratching my head. Why is the parameter value regarded as null, instead of 0? Enum LogEventType : int { SignIn, SignInFailure, SignOut, ... } private static DataTable QueryEventLogSession(DateTime start, DateTime stop) { DataTable entries = new DataTable(); using (FbConnection conn = new FbConnection(DSN)) { using (FbDataAdapter adapter = new FbDataAdapter( "SELECT event_type, event_timestamp, event_details FROM event_log " + "WHERE event_timestamp BETWEEN @start AND @stop " + "AND event_type IN (@signIn, @signInFailure, @signOut) " + "ORDER BY event_timestamp ASC", conn)) { adapter.SelectCommand.Parameters.AddRange(new Object[] { new FbParameter("@start", start), new FbParameter("@stop", stop), new FbParameter("@signIn", (Int32)LogEventType.SignIn), new FbParameter("@signInFailure", (Int32)LogEventType.SignInFailure), new FbParameter("@signOut", (Int32)LogEventType.SignOut)}); Trace.WriteLine(adapter.SelectCommand.CommandText); foreach (FbParameter p in adapter.SelectCommand.Parameters) { Trace.WriteLine(p.Value.ToString()); } adapter.Fill(entries); } } return entries; }

    Read the article

  • Query Parameter Value Is Null When Enum Item 0 is Cast to Int32

    - by Timothy
    When I use the first item in a zero-based Enum cast to Int32 as a query parameter, the parameter value is null. I've worked around it by simply setting the first item to a value of 1, but I was wondering though what's really going on here? This one has me scratching my head. Why does the parameter regarded the value as null, instead of 0? Enum LogEventType : int { SignIn, SignInFailure, SignOut, ... } private static DataTable QueryEventLogSession(DateTime start, DateTime stop) { DataTable entries = new DataTable(); using (FbConnection conn = new FbConnection(DSN)) { using (FbDataAdapter adapter = new FbDataAdapter( "SELECT event_type, event_timestamp, event_details FROM event_log " + "WHERE event_timestamp BETWEEN @start AND @stop " + "AND event_type IN (@signIn, @signInFailure, @signOut) " + "ORDER BY event_timestamp ASC", conn)) { adapter.SelectCommand.Parameters.AddRange(new Object[] { new FbParameter("@start", start), new FbParameter("@stop", stop), new FbParameter("@signIn", (Int32)LogEventType.SignIn), new FbParameter("@signInFailure", (Int32)LogEventType.SignInFailure), new FbParameter("@signOut", (Int32)LogEventType.SignOut)}); Trace.WriteLine(adapter.SelectCommand.CommandText); foreach (FbParameter p in adapter.SelectCommand.Parameters) { Trace.WriteLine(p.Value.ToString()); } adapter.Fill(entries); } } return entries; }

    Read the article

  • Public class: Makes pointer from integer without cast

    - by meridimus
    I have written a class to help save and load data for the sake of persistence for my iPhone application but I have a problem with some NSUIntegers that I'm passing across. Basically, I have the code to use pointers, but eventually it has to start out being an actual value right? So I get this error warning: passing argument 1 of 'getSaveWithCampaign:andLevel:' makes pointer from integer without a cast My code is laid out like so. (Persistence is the name of the class) NSDictionary *saveData = [Persistence getSaveWithCampaign:currentCampaign andLevel:[indexPath row]]; Here's Persistence.m #import "Persistence.h" @implementation Persistence + (NSString *)dataFilePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; return [documentsDirectory stringByAppendingPathComponent:kSaveFilename]; } + (NSDictionary *)getSaveWithCampaign:(NSUInteger *)campaign andLevel:(NSUInteger *)level { NSString *filePath = [self dataFilePath]; if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { NSDictionary *saveData = [[NSDictionary alloc] initWithContentsOfFile:filePath]; NSString *campaignAndLevelKey = [self makeCampaign:campaign andLevelKey:level]; NSDictionary *campaignAndLevelData = [saveData objectForKey:campaignAndLevelKey]; [saveData release]; return campaignAndLevelData; } else { return nil; } } + (NSString *)makeCampaign:(NSUInteger *)campaign andLevelKey:(NSUInteger *)level { return [[NSString stringWithFormat:@"%d - ", campaign+1] stringByAppendingString:[NSString stringWithFormat:@"%d", level+1]]; } @end

    Read the article

  • Cast exception being generated when using the same type of object

    - by David Tunnell
    I was previously using static variables to hold variable data that I want to save between postbacks. I was having problems and found that the data in these variables is lost when the appdomain ends. So I did some research and decided to go with ViewStates: static Dictionary<string, linkButtonObject> linkButtonDictonary; protected void Page_Load(object sender, EventArgs e) { if (ViewState["linkButtonDictonary"] != null) { linkButtonDictonary = (Dictionary<string, linkButtonObject>)ViewState["linkButtonDictonary"]; } else { linkButtonDictonary = new Dictionary<string, linkButtonObject>(); } } And here is the very simple class I use: [Serializable] public class linkButtonObject { public string storyNumber { get; set; } public string TaskName { get; set; } } I am adding to linkButtonDictionary as a gridview is databound: protected void hoursReportGridView_OnRowDataBound(Object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { LinkButton btn = (LinkButton)e.Row.FindControl("taskLinkButton"); linkButtonObject currentRow = new linkButtonObject(); currentRow.storyNumber = e.Row.Cells[3].Text; currentRow.TaskName = e.Row.Cells[5].Text; linkButtonDictonary.Add(btn.UniqueID, currentRow); } } It appears that my previous issues are resolved however a new one has arisin. Sometime when I postback I am getting this error: [A]System.Collections.Generic.Dictionary2[System.String,linkButtonObject] cannot be cast to [B]System.Collections.Generic.Dictionary2[System.String,linkButtonObject]. Type A originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Type B originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. I don't understand how there can be a casting issue when I am using the same class everywhere. What am I doing wrong and how do I fix it?

    Read the article

  • Resharper and var

    - by Refracted Paladin
    I have Resharper 4.5 and have found it invaluable so far but I have a concern; It seems to want to make every variable declaration implicit(var). As a relativly new developer how much should I trust ReSharper when it comes to this? Take the below code snippet from a method that Paints Tab Headers. TabPage currentTab = tabCaseNotes.TabPages[e.Index]; Rectangle itemRect = tabCaseNotes.GetTabRect(e.Index); SolidBrush fillBrush = new SolidBrush(Color.Linen); SolidBrush textBrush = new SolidBrush(Color.Black); StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; Resharper wants me to change all 5 of those to var. I have read the following similar post,Use of var keyword in C#, but I would like to know from a Resharper standpoint. Thanks!

    Read the article

  • Why does this explicit call of a Scala method allow it to be implicitly resolved?

    - by Matt R
    Why does this code fail to compile, but compiles successfully when I uncomment the indicated line? (I'm using Scala 2.8 nightly). It seems that explicitly calling string2Wrapper allows it to be used implicitly from that point on. class A { import Implicits.string2Wrapper def foo() { //string2Wrapper("A") ==> "B" // <-- uncomment } def bar() { "A" ==> "B" "B" ==> "C" "C" ==> "D" } object Implicits { implicit def string2Wrapper(s: String) = new Wrapper(s) class Wrapper(s: String) { def ==>(s2: String) {} } } }

    Read the article

  • class classname(value); & class classname=value; difference when constructor is explicit

    - by Mahesh
    When constructor is explicit, it isn't used for implicit conversions. In the given snippet, constructor is marked as explicit. Then why in case foo obj1(10.25); it is working and in foo obj2=10.25; it isn't working ? #include <iostream> class foo { int x; public: explicit foo( int x ):x(x) {} }; int main() { foo obj(10.25); // Not an error. Why ? foo obj2 = 10.25; // Error getchar(); return 0; } error: error C2440: 'initializing' : cannot convert from 'double' to 'foo'

    Read the article

  • Using XMLDecoder to cast Encoded XML to List<>

    - by Ender
    I am writing an application that reads in a large number of basic user details in the following format; once read in it then allows the user to search for a user's details using their email: NAME ROLE EMAIL --------------------------------------------------- Joe Bloggs Manager [email protected] John Smith Consultant [email protected] Alan Wright Tester [email protected] ... The problem I am suffering is that I need to store a large number of details of all people that have worked at the company. The file containing these details will be written on a yearly basis simply for reporting purposes, but the program will need to be able to access these details quickly. The way I aim to access these files is to have a program that asks the user for the name of the unique email of the member of staff and for the program to then return the name and the role from that line of the file. I've played around with text files, but am struggling with how I would handle multiple columns of data when it comes to searching this large file. What is the best format to store such data in? A text file? XML? The size doesn't bother me, but I'd like to be able to search it as quickly as possible. The file will need to contain a lot of entries, probably over the 10K mark over time. EDIT: I've decided to go with the XML serialisation method. I've managed to get the code for Encoding working perfectly, but the Decoding code below does not work. XMLDecoder d = new XMLDecoder( new BufferedInputStream(new FileInputStream("data.xml"))); List<Employee> list = (List<Employee>) d.readObject(); d.close(); for(Employee x : list) { if(x.getEmail().equals(userInput)) { // do stuff } } When the program hits List<Employee> list = (List<Employee>) d.readObject(); an exception is thrown claiming that "Employee cannot be cast to java.util.List". I've added a bounty to this and anyone that can help me solve this problem once and for all will get lots of lovely points. EDIT 2: I've looked a bit more into the problem and have come across Serialization as a potential answer. If anyone can look into this for me as I've no experience with Serialization or Deserialization I'd be very grateful. It can provide an Object with no problems whatsoever, but I really need to return it in the same format as it went in (List). EDIT 3: Ugh, this problem is really starting to drive me crazy and to be honest I'm starting to think that it's an unsolvable problem. If possible, could someone take a look at the code and help provide a solution for me?

    Read the article

  • Python - integer to byte

    - by quano
    Say I've got an integer, 13941412, that I wish to separate into bytes (the number is actually a color in the form 0x00bbggrr). How would you do that? In c, you'd cast the number to a BYTE and then shift the bits. How do you cast to byte in Python?

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >