|
especially if you look at the poster's profile
Best,
John
|
|
|
|
|
i'm a newbie in IT and i'm learning C program.i'm wrote this code and it has error message.
-------
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i;
long s;
scanf ("%d" ,&n);
s=0;
i=1;
while (i<=n)
{
s=s+i;
i=i+1;
}
printf("%ld",s);
}
modified 13-Oct-15 11:37am.
|
|
|
|
|
What is the error message you are getting? Also, in future posts, use a more descriptive subject line, and place in the correct forum since you have a C program problem and this is the C# forum.
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
I just built and ran your code and there are no error messages. There is one warning about using scanf_s instead of scanf , but that can be safely ignored for now.
I suggest you post the full details in the C forum, making sure you include the exact text of the error message.
|
|
|
|
|
Windows Forms
Let'say you have a List<Control> : some of those Controls' Native Types have the 'FlatStyle Property; others may have the 'BorderStyle Property; other Controls may have neither. Of course we know that the Button Control, for example, inherits from ButtonBase which inherits from Control, etc.
At run-time we can use reflection to determine if a Control is of a Type that contains a specific Property, and, if the Property exists, get its DeclaringType:
PropertyInfo pif = currentControl.GetType().GetProperty("BorderStyle");
if (pif != null)
{
Type typ = pif.DeclaringType;
} If we want to set the 'BorderStyle of the Control at this point, obviously we have to cast it, somehow, back to its Native Type.
But, how ?
thanks, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
One way I have seen this done, albeit in a hacky way, is to provide a Cast method that looks something like this:
public T Cast<T>(object o)
{
return (T)o;
} Then, you call it with this:
MethodInfo methodInfo = this.GetType().GetMethod("Cast").MakeGenericMethod(typ); You can then choose to do with it, what you will.
modified 13-Oct-15 8:20am.
|
|
|
|
|
Thanks, Pete, I am drawing a blank here about how you would use the 'MethodInfo created in your code. I'm trying this:
public T XCast<T>(object o)
{
return (T)o;
}
Type typ = currentControl.GetType();
MethodInfo methodInfo = this.GetType().GetMethod("XCast").MakeGenericMethod(typ);
var xc = methodInfo.Invoke(currentControl, null);
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Your invoke should look something like this:
methodInfo.Invoke(null, new object[] { button }); But, as Eddy has rightly pointed out - you can always use GetValue and SetValue.
|
|
|
|
|
Thanks, Pete, Eddy's suggestion does enable me to do what I want, but I am still curious about your code; if I use this:
public T XCast<T>(object o)
{
return (T)o;
}
PropertyInfo pif = currentControl.GetType().GetProperty("BorderStyle");
if (pif != null)
{
Type typ = currentControl.GetType();
MethodInfo methodInfo = this.GetType().GetMethod("XCast").MakeGenericMethod(typ);
var xc = methodInfo.Invoke(this, new object[]{currentControl});
} Then 'xc does appear to have a valid reference to the Control with the BorderStyle Property, but to set that Property: of course, I can't use 'xc.
Is there a "missing piece" of the puzzle here that would let me set the Property without using 'SetValue ?
thanks, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
BillWoodruff wrote: If we want to set the 'BorderStyle of the Control at this point, obviously we have to cast it, somehow, back to its Native Type. No need to cast, just to get or set the property. If you have the PropertyInfo , then you can call its GetValue method.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Excellent, Eddy, as is said in the American South (where I was raised): "if that had been a snake, it would've bit you."
Everytime I make a mistake of omitting to look for the simpler way, I hear the introduction to "Proud Mary" spoken by Tina Turner:
"But there's just one thing
You see we never ever do nothing
Nice, easy"
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Tx, and you're welcome. Just a lucky open spot in the grass where the snake was easy to see
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have created a .mdf database file. I have created a table and populated It with rows.
Im trying to use Entity framework, to comunicate with the database.
Here, Im using a context to connect to the database:
namespace SportsStore.domain.Concrete
{
public class EFDbContext : DbContext
{
public DbSet<Product> Products { get; set; }
}
}
And here, Im trying to get the rows from the database:
namespace SportsStore.domain.Concrete
{
public class EFProductRepository : IProductRepository
{
private EFDbContext context = new EFDbContext();
public IEnumerable<Product> Products
{
get { return context.Products; }
}
}
}
When I run my application, nothing Is printed out. The rows from the database are not printed out.
Anyone who can help me with this? Should I add something to Web.Config? If so, what should I add?
|
|
|
|
|
You haven't shown all the relevant code so it's impossible to be sure why it's not working.
But, I will say that your repository code doesn't return an IEnumerable<Product> . Your code is actually returning a DbSet<Product> , which just so happens to implement IEnumberable<TEntity> so the code doesn't throw an error when you compile it.
The set you're returning is empty because the query hasn't actually run. You have to call some method on the Products query, typically .ToList() , to force the query to run and build the list in memory. It's called "deferred execution[^]". If you're using Entity Framework you better understand what this is.
Your repository should looks more like this:
namespace SportsStore.domain.Concrete
{
public class EFProductRepository : IProductRepository
{
private EFDbContext context = new EFDbContext();
public IEnumerable<Product> Products
{
get { return context.Products.ToList(); }
}
}
}
|
|
|
|
|
Sorry. That did not help me. Someone else?`
|
|
|
|
|
Lie I said, you have not supplied all the relevant code, such as your View and Controller code.
|
|
|
|
|
When I add ToList(), I get the following error:
Additional information: Failed to set database initializer of type 'SportsStore.domain.Concrete, EFProductRepository' for DbContext type 'SportsStore.domain.Concrete, EFDbContext' specified in the application configuration. See inner exception for details.
Does this mean that I have to add a line to my Web.Config file?
|
|
|
|
|
And the inner exception message is .......?
Also, what IS in your Web.Config file?
|
|
|
|
|
The message of my inner exception says: "Can not load file or assembly EFDbContext or one of its dependencies. The system can not find the file EFDbContext"
Here is my Web.Config:
="1.0"="utf-8"
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
<entityFramework>
<contexts>
<context type="SportsStore.domain.Concrete, EFDbContext">
<databaseInitializer type="SportsStore.domain.Concrete, EFProductRepository" />
</context>
</contexts>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
|
|
|
|
|
Your <context> and <databaseInitializer> lines are wrong. They're saying "look for a class called 'SportsStore.domain.Concrete' in the assembly 'EFProductRepository' in one line and in 'EFProductRepository' in the other. That's not what the class is called nor where to find it.
I think it should be more like:
<contexts>
<context type="SportsStore.domain.Concrete.EFDbContext, assemblyNameGoesHere!">
<databaseInitializer type="SportsStore.domain.Concrete.initializerClassNameGoesHere, assemblyNameGoesHere!" />
</context>
</contexts>
It's impossible to provide the exact names because you haven't provided enough information. But, you have to fill in the missing initializer class name that you wrote to initialize the database and the assembly names that contain the specified classes.
|
|
|
|
|
And what Is assemblyNameGoesHere and initializerClassName?
What kind of more information do you need?
|
|
|
|
|
I already said. The assembly name is the name of the assembly the class can be found in, usually the project name without any spaces.
The initializer class name is the name of the class that contains whatever initializer code you wrote.
If there isn't one, you can just remove the entire <context> section in the Web.config.
|
|
|
|
|
Hi
I want read latitude and longitude from gps device in .net .Please share code if possible.
Thanks
|
|
|
|
|
We're not a code writing service and we're not here to do your research for you.
Google for "C# TK103 GPS" and see what you get.
|
|
|
|
|
I would check the documentation and website of the manufacturer.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|